Skip to content

Commit

Permalink
build: use purple merge instead of close on CQ
Browse files Browse the repository at this point in the history
If the bot can make modifications to the head branch, force push to the
head branch so it lands with the purple icon on GitHub instead of the
red icon when the PR is closed. Let's gooooooooo!

Ref: nodejs/node-core-utils#264
  • Loading branch information
mmarchini authored and aduh95 committed Oct 9, 2020
1 parent e079374 commit 043af6e
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion tools/actions/commit-queue.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ API_URL=https://api.github.com
COMMIT_QUEUE_LABEL='commit-queue'
COMMIT_QUEUE_FAILED_LABEL='commit-queue-failed'

function prUrl() {
echo "$API_URL/repos/${OWNER}/${REPOSITORY}/pulls/${1}"
}

function issueUrl() {
echo "$API_URL/repos/${OWNER}/${REPOSITORY}/issues/${1}"
}
Expand Down Expand Up @@ -80,13 +84,21 @@ for pr in "$@"; do
git node land --abort --yes
else
rm output
head=$(gitHubCurl "$(prUrl "$pr")" GET | jq '{ ref: .head.ref, remote: .head.repo.ssh_url, can_modify: .maintainer_can_modify }')
if [ "$(echo "$head" | jq -r .can_modify)" == "true" ]; then
git push --force "$(echo "$head" | jq -r .remote)" master:"$(echo "$head" | jq -r .ref)"
# Give GitHub time to sync before pushing to master
sleep 60s
fi

commits="$(git rev-parse $UPSTREAM/$DEFAULT_BRANCH)...$(git rev-parse HEAD)"

git push $UPSTREAM $DEFAULT_BRANCH

gitHubCurl "$(commentsUrl "$pr")" POST --data '{"body": "Landed in '"$commits"'"}'

gitHubCurl "$(issueUrl "$pr")" PATCH --data '{"state": "closed"}'
if [ "$(echo "$head" | jq -r .can_modify)" != "true" ]; then
gitHubCurl "$(issueUrl "$pr")" PATCH --data '{"state": "closed"}'
fi
fi
done

0 comments on commit 043af6e

Please sign in to comment.