Skip to content

Commit

Permalink
tools: use GitHub Squash and Merge feature when using CQ
Browse files Browse the repository at this point in the history
  • Loading branch information
aduh95 committed Oct 30, 2021
1 parent f7a3c49 commit b345942
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions tools/actions/commit-queue.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ issueUrl() {
echo "$API_URL/repos/${OWNER}/${REPOSITORY}/issues/${1}"
}

mergeUrl() {
echo "$API_URL/repos/${OWNER}/${REPOSITORY}/pulls/${1}/merge"
}

labelsUrl() {
echo "$(issueUrl "${1}")/labels"
}
Expand Down Expand Up @@ -92,12 +96,25 @@ for pr in "$@"; do
git node land --abort --yes
continue
fi

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

if ! git push $UPSTREAM $DEFAULT_BRANCH >> output 2>&1; then
commit_queue_failed "$pr"
continue
if [ -z "$MULTIPLE_COMMIT_POLICY" ]; then
commits="$(git rev-parse $UPSTREAM/$DEFAULT_BRANCH)...$(git rev-parse HEAD)"

if ! git push $UPSTREAM $DEFAULT_BRANCH >> output 2>&1; then
commit_queue_failed "$pr"
continue
fi
else
# If there's only one commit, we can use the Squash and Merge feature from GitHub
gitHubCurl "$(mergeUrl "$pr")" PUT --data "$(\
TITLE="$(git log -1 --pretty='format:%s')" \
BODY="$(git log -1 --pretty='format:%b')" \
node -p 'JSON.stringify({merge_method:"squash",commit_title:process.env.TITLE,commit_message: process.env.BODY})')" > response.json
cat response.json
if ! commits="$(node -e 'const r=require("./response.json");if(!r.merged)throw new Error("Merging failed");process.stdout.write(r.sha)')"; then
commit_queue_failed "$pr"
continue
fi
fi

rm output
Expand Down

0 comments on commit b345942

Please sign in to comment.