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 committed Aug 31, 2020
1 parent 75d943e commit 77a9be9
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 @@ -11,6 +11,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 @@ -76,10 +80,18 @@ 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 5s
fi
git push origin master

gitHubCurl "$(commentsUrl "$pr")" POST --data '{"body": "Landed in '"$(git rev-parse HEAD)"'"}'

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 77a9be9

Please sign in to comment.