@@ -4,62 +4,39 @@ set -xe
44
55OWNER=$1
66REPOSITORY=$2
7- GITHUB_TOKEN=$3
8- shift 3
7+ shift 2
98
109UPSTREAM=origin
1110DEFAULT_BRANCH=master
1211
13- API_URL=https://api.github.com
14- COMMIT_QUEUE_LABEL=' commit-queue'
15- COMMIT_QUEUE_FAILED_LABEL=' commit-queue-failed'
16-
17- issueUrl () {
18- echo " $API_URL /repos/${OWNER} /${REPOSITORY} /issues/${1} "
19- }
12+ COMMIT_QUEUE_LABEL=" commit-queue"
13+ COMMIT_QUEUE_FAILED_LABEL=" commit-queue-failed"
2014
2115mergeUrl () {
22- echo " $API_URL /repos/${OWNER} /${REPOSITORY} /pulls/${1} /merge"
23- }
24-
25- labelsUrl () {
26- echo " $( issueUrl " ${1} " ) /labels"
27- }
28-
29- commentsUrl () {
30- echo " $( issueUrl " ${1} " ) /comments"
31- }
32-
33- gitHubCurl () {
34- url=$1
35- method=$2
36- shift 2
37-
38- curl -fsL --request " $method " \
39- --url " $url " \
40- --header " authorization: Bearer ${GITHUB_TOKEN} " \
41- --header ' content-type: application/json' " $@ "
16+ echo " repos/${OWNER} /${REPOSITORY} /pulls/${1} /merge"
4217}
4318
4419commit_queue_failed () {
45- gitHubCurl " $( labelsUrl " ${1} " ) " POST --data ' {"labels": ["' " ${COMMIT_QUEUE_FAILED_LABEL} " ' "]}'
20+ pr=$1
21+
22+ gh pr edit " $pr " --add-label " ${COMMIT_QUEUE_FAILED_LABEL} "
4623
4724 # shellcheck disable=SC2154
4825 cqurl=" ${GITHUB_SERVER_URL} /${OWNER} /${REPOSITORY} /actions/runs/${GITHUB_RUN_ID} "
49- jq -n --arg content " <details><summary>Commit Queue failed</summary><pre>$( cat output) </pre><a href='$cqurl '>$cqurl </a></details>" ' {body: $content} ' > output.json
50- cat output.json
26+ body= " <details><summary>Commit Queue failed</summary><pre>$( cat output) </pre><a href='$cqurl '>$cqurl </a></details>"
27+ echo " $body "
5128
52- gitHubCurl " $( commentsUrl " ${1} " ) " POST --data @output.json
29+ gh pr comment " $pr " --body " $body "
5330
54- rm output output.json
31+ rm output
5532}
5633
5734# TODO(mmarchini): should this be set with whoever added the label for each PR?
5835git config --local user.email " github-bot@iojs.org"
5936git config --local user.name " Node.js GitHub Bot"
6037
6138for pr in " $@ " ; do
62- gitHubCurl " $( labelsUrl " $pr " ) " GET > labels.json
39+ gh pr view " $pr " --json labels --jq " .labels " > labels.json
6340 # Skip PR if CI was requested
6441 if jq -e ' map(.name) | index("request-ci")' < labels.json; then
6542 echo " pr ${pr} skipped, waiting for CI to start"
@@ -73,7 +50,7 @@ for pr in "$@"; do
7350 fi
7451
7552 # Delete the commit queue label
76- gitHubCurl " $( labelsUrl " $pr " ) " / " $COMMIT_QUEUE_LABEL " DELETE
53+ gh pr edit " $pr " --remove-label " $COMMIT_QUEUE_LABEL "
7754
7855 if jq -e ' map(.name) | index("commit-queue-squash")' < labels.json; then
7956 MULTIPLE_COMMIT_POLICY=" --fixupAll"
@@ -106,14 +83,18 @@ for pr in "$@"; do
10683 continue
10784 fi
10885 else
109- # If there's only one commit, we can use the Squash and Merge feature from GitHub
86+ # If there's only one commit, we can use the Squash and Merge feature from GitHub.
87+ # TODO: use `gh pr merge` when the GitHub CLI allows to customize the commit title (https://github.com/cli/cli/issues/1023).
11088 jq -n \
11189 --arg title " $( git log -1 --pretty=' format:%s' ) " \
11290 --arg body " $( git log -1 --pretty=' format:%b' ) " \
11391 --arg head " $( grep ' Fetched commits as' output | cut -d. -f3 | xargs git rev-parse) " \
11492 ' {merge_method:"squash",commit_title:$title,commit_message:$body,sha:$head}' > output.json
11593 cat output.json
116- gitHubCurl " $( mergeUrl " $pr " ) " PUT --data @output.json > output
94+ if ! gh api -X PUT " $( mergeUrl " $pr " ) " --input output.json > output; then
95+ commit_queue_failed " $pr "
96+ continue
97+ fi
11798 cat output
11899 if ! commits=" $( jq -r ' if .merged then .sha else error("not merged") end' < output) " ; then
119100 commit_queue_failed " $pr "
@@ -124,9 +105,9 @@ for pr in "$@"; do
124105
125106 rm output
126107
127- gitHubCurl " $( commentsUrl " $pr " ) " POST --data ' {" body": "Landed in ' " $commits " ' "} '
108+ gh pr comment " $pr " -- body " Landed in $commits "
128109
129- [ -z " $MULTIPLE_COMMIT_POLICY " ] && gitHubCurl " $( issueUrl " $pr " ) " PATCH --data ' {"state": "closed"} '
110+ [ -z " $MULTIPLE_COMMIT_POLICY " ] && gh pr close " $pr "
130111done
131112
132113rm -f labels.json
0 commit comments