From 77a9be95af9ff7348f8fb1c2be11577015c849f1 Mon Sep 17 00:00:00 2001 From: Mary Marchini Date: Mon, 31 Aug 2020 14:48:46 -0700 Subject: [PATCH] build: use purple merge instead of close on CQ 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: https://github.com/nodejs/node-core-utils/issues/264 --- tools/actions/commit-queue.sh | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/tools/actions/commit-queue.sh b/tools/actions/commit-queue.sh index 028297217469a0..d4c73a0dbd0b5b 100755 --- a/tools/actions/commit-queue.sh +++ b/tools/actions/commit-queue.sh @@ -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}" } @@ -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