Skip to content

Commit

Permalink
set merge branch consistently between check and in
Browse files Browse the repository at this point in the history
Remove using "rev-list"  to get source/target commit for PRs
Emulate pull-request/*/merge for bitBucket 7
  • Loading branch information
ywei2017 committed May 10, 2022
1 parent 0cecdfa commit ff74f39
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
11 changes: 7 additions & 4 deletions assets/helpers/git.sh
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,17 @@ pullrequest_metadata() {
# $1: pull request number
# $2: pull request repository
# $3: skip ssl verification
# $4: soucre_commmit
# $5: target_commmit

local source_commit=$(git rev-list --parents -1 $(git rev-parse HEAD) | awk '{print $3}')
local target_commit=$(git rev-list --parents -1 $(git rev-parse HEAD) | awk '{print $2}')
# No longer working with vSphere 7
#local source_commit=$(git rev-list --parents -1 $(git rev-parse HEAD) | awk '{print $3}')
#local target_commit=$(git rev-list --parents -1 $(git rev-parse HEAD) | awk '{print $2}')

jq -n "[]" | \
add_pullrequest_metadata_basic "$1" "$2" "$3" | \
add_pullrequest_metadata_commit "source" "$source_commit" | \
add_pullrequest_metadata_commit "target" "$target_commit"
add_pullrequest_metadata_commit "source" "$4" | \
add_pullrequest_metadata_commit "target" "$5"
}

configure_credentials() {
Expand Down
19 changes: 14 additions & 5 deletions assets/in
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,13 @@ if test "$depth" -gt 0 2> /dev/null; then
depthflag="--depth $depth"
fi

branch="pull-requests/${prq_id}/merge"
# see comments in "check" resource
branch="pull-requests/${prq_id}"
if [ "$rebuild_when_target_changed" == "true" ]; then
branch="$branch/merge"
else
branch="$branch/from"
fi

log "Cloning $uri in $destination"
git clone $depthflag "$uri" "$destination"
Expand Down Expand Up @@ -133,7 +139,7 @@ prq=$(bitbucket_pullrequest "$repo_host" "$repo_project" "$repo_name" "$prq_id"
if [ "$prq" != "NO_SUCH_PULL_REQUEST" ] && \
[ "$prq" != "ALREADY_MERGED" ] && \
[ "$prq" != "DECLINED" ]; then
branch=$(echo "$prq" | jq -r '.fromRef.displayId')
from_branch=$(echo "$prq" | jq -r '.fromRef.displayId')
fi

# calculate source and target commit
Expand All @@ -149,17 +155,20 @@ if [ -z "$target_commit" ]; then
exit 1
fi


if [[ "$branch" == */from ]]; then
log "Merge in changes from $target_commit to pullrequest/*/from, to emulate pullrequest/*/merge"
git merge $target_commit
fi

# expose configuration of pull request that can be used in container
git config --add pullrequest.id $prq_id
git config --add pullrequest.source $source_commit
git config --add pullrequest.target $target_commit
git config --add pullrequest.merge $ref
git config --add pullrequest.date "$prq_date"
git config --add pullrequest.branch "$branch"
git config --add pullrequest.branch "$from_branch"

jq -n "{
version: $(jq '.version' < "$payload"),
metadata: $(pullrequest_metadata "$prq_id" "$uri" "$skip_ssl_verification")
metadata: $(pullrequest_metadata "$prq_id" "$uri" "$skip_ssl_verification" "$source_commit" "$target_commit" )
}" >&3
2 changes: 1 addition & 1 deletion assets/out
Original file line number Diff line number Diff line change
Expand Up @@ -191,5 +191,5 @@ jq -n "{
hash: \"$prq_hash\",
date: \"$PULL_REQUEST_DATE\"
},
metadata: $(pullrequest_metadata "$prq_number" "$uri" "$skip_ssl_verification")
metadata: $(pullrequest_metadata "$prq_number" "$uri" "$skip_ssl_verification" "$source_commit" "$target_commit" )
}" >&3

0 comments on commit ff74f39

Please sign in to comment.