From 043af6e114b8431b16820d5796162eaa6a8f5757 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 ec247506796..b12267f74bd 100755 --- a/tools/actions/commit-queue.sh +++ b/tools/actions/commit-queue.sh @@ -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}" } @@ -80,6 +84,12 @@ 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)" @@ -87,6 +97,8 @@ for pr in "$@"; do 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