Skip to content

Commit e8633dd

Browse files
committed
tools: use github cli to squash the pr
1 parent 93644d5 commit e8633dd

File tree

2 files changed

+5
-19
lines changed

2 files changed

+5
-19
lines changed

Diff for: tools/actions/commit-queue.sh

+1-9
Original file line numberDiff line numberDiff line change
@@ -82,18 +82,11 @@ for pr in "$@"; do
8282
fi
8383
else
8484
# If there's only one commit, we can use the Squash and Merge feature from GitHub.
85-
# TODO: use `gh pr merge` when the GitHub CLI allows to customize the commit title (https://github.com/cli/cli/issues/1023).
8685
commit_title=$(git log -1 --pretty='format:%s')
8786
commit_body=$(git log -1 --pretty='format:%b')
8887
commit_head=$(grep 'Fetched commits as' output | cut -d. -f3 | xargs git rev-parse)
8988

90-
jq -n \
91-
--arg title "${commit_title}" \
92-
--arg body "${commit_body}" \
93-
--arg head "${commit_head}" \
94-
'{merge_method:"squash",commit_title:$title,commit_message:$body,sha:$head}' > output.json
95-
cat output.json
96-
if ! gh api -X PUT "repos/${OWNER}/${REPOSITORY}/pulls/${pr}/merge" --input output.json > output; then
89+
if ! gh pr merge "$pr" --squash --body "$commit_body" --subject "$commit_title" --match-head-commit "$commit_head" --admin > output; then
9790
commit_queue_failed "$pr"
9891
continue
9992
fi
@@ -102,7 +95,6 @@ for pr in "$@"; do
10295
commit_queue_failed "$pr"
10396
continue
10497
fi
105-
rm output.json
10698
fi
10799

108100
rm output

Diff for: tools/actions/merge.sh

+4-10
Original file line numberDiff line numberDiff line change
@@ -39,24 +39,18 @@ git log -1 HEAD^ --pretty='format:%B' | git interpret-trailers --parse --no-divi
3939
commit_title=$(git log -1 --pretty='format:%s')
4040
commit_body=$(git log -1 --pretty='format:%b')
4141

42-
jq -n \
43-
--arg title "${commit_title}" \
44-
--arg body "${commit_body}" \
45-
--arg head "${commit_head}" \
46-
'{merge_method:"squash",commit_title:$title,commit_message:$body,sha:$head}' > output.json
47-
cat output.json
48-
if ! gh api -X PUT "repos/${OWNER}/${REPOSITORY}/pulls/${pr}/merge" --input output.json > output; then
42+
if ! gh pr merge "$pr" --squash --body "$commit_body" --subject "$commit_title" --match-head-commit "$commit_head" --admin > output; then
4943
cat output
5044
echo "Failed to merge $pr"
51-
rm output output.json
45+
rm output
5246
exit 1
5347
fi
5448
cat output
5549
if ! commits="$(jq -r 'if .merged then .sha else error("not merged") end' < output)"; then
5650
echo "Failed to merge $pr"
57-
rm output output.json
51+
rm output
5852
exit 1
5953
fi
60-
rm output.json output
54+
rm output
6155

6256
gh pr comment "$pr" --repo "$OWNER/$REPOSITORY" --body "Landed in $commits"

0 commit comments

Comments
 (0)