Skip to content

Commit 60537f5

Browse files
author
Matthew Boedicker
committed
Always use pull request date for version date
This commit fixes two issues: 1. If a git commit is amended and pushed after the PR is open, the put to update the PR status will trigger additional builds. This is because the date in the version in out is from the git commit which does not match the PR date output by check. 2. In progress PRs were never skipped because in check containers BUILD_ variables are not set. RESOURCE_ variables are set instead but there is no guarantee that the resource name matches the job name. This change makes check search comments using a smaller string that does not depend on BUILD_ variables.
1 parent 57eaa1d commit 60537f5

File tree

4 files changed

+17
-5
lines changed

4 files changed

+17
-5
lines changed

assets/check

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ if [ -n "$pull_requests" ]; then
110110
text=$(echo "$comment" | jq -r '.text')
111111

112112
# check for progress or finished messages => do not include in versions when available
113-
if bitbucket_pullrequest_progress_commit_match "$text" "$prq_hash"; then
113+
if bitbucket_pullrequest_comment_commit_match "$text" "$prq_hash"; then
114114
log "Skipping PRQ #$prq_number since already handled"
115115
skip_build=true
116116
break

assets/helpers/bitbucket.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,16 @@ bitbucket_pullrequest_progress_commit_match() {
143143
echo "$comment" | grep -Ec "^$(regex_escape "$msg")" > /dev/null
144144
}
145145

146+
bitbucket_pullrequest_comment_commit_match() {
147+
# $1: pull request comment
148+
# $2: pull request hash
149+
local comment="$1"
150+
local hash="$2"
151+
152+
local msg=")** for $hash into"
153+
echo "$comment" | grep -Ec "$(regex_escape "$msg")" > /dev/null
154+
}
155+
146156
bitbucket_pullrequest_progress_comment() {
147157
# $1: status (success, failure or pending)
148158
# $2: hash of merge commit

assets/in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ submodules=$(jq -r '(.params.submodules // "all")' < "$payload")
4545
disable_git_lfs=$(jq -r '(.params.disable_git_lfs // false)' < "$payload")
4646

4747
prq_id=$(jq -r '.version.id // ""' < "$payload")
48+
prq_date=$(jq -r '.version.date // ""' < "$payload")
4849

4950
configure_git_ssl_verification "$skip_ssl_verification"
5051
configure_git_global "${git_config_payload}"
@@ -136,6 +137,7 @@ git config --add pullrequest.id $prq_id
136137
git config --add pullrequest.source $source_commit
137138
git config --add pullrequest.target $target_commit
138139
git config --add pullrequest.merge $ref
140+
git config --add pullrequest.date "$prq_date"
139141

140142
jq -n "{
141143
version: $(jq '.version' < "$payload"),

assets/out

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,8 @@ data=$(jq -cn "{
140140
# set commit build status for source commit
141141
bitbucket_pullrequest_commit_status "$repo_host" "$source_commit" "$data" "" "" "$skip_ssl_verification"
142142

143-
# use the current commit timestamp as date
144-
prq_verify_date=$(git log -1 --format=format:%at)
143+
# use the pullrequest date stored in git config in get
144+
prq_verify_date=$(git config --get pullrequest.date | cat)
145145

146146
# add comment to pull request to track if build was started/finished
147147
comment_message=$(bitbucket_pullrequest_progress_comment "$status" "$prq_hash" "$source_commit" "$target_commit")
@@ -165,7 +165,7 @@ if [ -n "$comments" ]; then
165165
# edit timestamp to force new build when rebuild_phrase is included in comments
166166
if [ "$skip_verify" != "true" ]; then
167167
if echo "$text" | grep -Ec "$rebuild_phrase" > /dev/null; then
168-
prq_verify_date=$(( ($(echo "$comment" | jq -r '.createdDate') + 500) / 1000))
168+
prq_verify_date=$(date_from_epoch_seconds $(( ($(echo "$comment" | jq -r '.createdDate') + 500) / 1000)))
169169
skip_verify=true
170170
fi
171171
fi
@@ -184,7 +184,7 @@ jq -n "{
184184
version: {
185185
id: \"$prq_number\",
186186
hash: \"$prq_hash\",
187-
date: \"$(date_from_epoch_seconds "$prq_verify_date")\"
187+
date: \"$prq_verify_date\"
188188
},
189189
metadata: $(pullrequest_metadata "$prq_number" "$uri" "$skip_ssl_verification")
190190
}" >&3

0 commit comments

Comments
 (0)