Skip to content

Commit c400d46

Browse files
committed
tools: improve backport review script
Signed-off-by: Antoine du Hamel <duhamelantoine1995@gmail.com> PR-URL: #62573 Reviewed-By: Filip Skokan <panva.ip@gmail.com>
1 parent 978afea commit c400d46

1 file changed

Lines changed: 24 additions & 7 deletions

File tree

‎tools/actions/review_backport.sh‎

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,16 @@
22

33
BACKPORT_PR=$1
44

5+
[ -x"$(command -v gh || true)" ] || {
6+
# shellcheck disable=SC2016
7+
echo'Missing required `gh` dependency'>&2
8+
exit 1
9+
}
510
[ -n"$BACKPORT_PR" ] || {
6-
echo"Usage:"
7-
echo'tools/actions/review_backport.sh https://github.com/nodejs/node/pull/<backport-PR-number> | less'
8-
echo'DIFF_CMD="codium --wait --diff" tools/actions/review_backport.sh https://github.com/nodejs/node/pull/<backport-PR-number>'
9-
echo"Limitations: This tools only supports PRs that landed as single commit, e.g. with 'commit-queue-squash' label."
11+
echo"Usage:">&2
12+
echo'tools/actions/review_backport.sh https://github.com/nodejs/node/pull/<backport-PR-number> | less'>&2
13+
echo'DIFF_CMD="codium --wait --diff" tools/actions/review_backport.sh https://github.com/nodejs/node/pull/<backport-PR-number>'>&2
14+
echo"Limitations: This tools only supports PRs that landed as single commit, e.g. with 'commit-queue-squash' label.">&2
1015

1116
exit 1
1217
}
@@ -15,16 +20,28 @@ SED_CMD='s/^index [a-f0-9]\+..[a-f0-9]\+ \([0-7]\{6\}\)$/index eeeeeeeeee..eeeee
1520

1621
set -ex
1722

23+
BACKPORT_PR_URL=$(gh pr view "$BACKPORT_PR" --json url --jq .url)
24+
1825
ORIGINAL=$(mktemp)
1926
BACKPORT=$(mktemp)
27+
trap'set -x; rm -f "$ORIGINAL" "$BACKPORT"; set +x; trap - EXIT; exit' EXIT INT HUP
28+
2029
gh pr view "$BACKPORT_PR" --json commits --jq '.[] | map([ .oid, (.messageBody | match("(?:^|\\n)PR-URL: (https?://.+/pull/\\d+)(?:\\n|$)", "g") | .captures | last | .string)] | @tsv) | .[]' \
2130
|whileread -r LINE;do
2231
COMMIT_SHA=$(echo "$LINE"| cut -f1)
2332
PR_URL=$(echo "$LINE"| cut -f2)
2433

2534
curl -fsL "$PR_URL.diff"| sed "$SED_CMD">>"$ORIGINAL"
26-
curl -fsL "$BACKPORT_PR/commits/$COMMIT_SHA.diff"| sed "$SED_CMD">>"$BACKPORT"
35+
curl -fsL "$BACKPORT_PR_URL/commits/$COMMIT_SHA.diff"| sed "$SED_CMD">>"$BACKPORT"
2736
done
2837

29-
${DIFF_CMD:-diff}"$ORIGINAL""$BACKPORT"
30-
rm "$ORIGINAL""$BACKPORT"
38+
${DIFF_CMD:-diff}"$ORIGINAL""$BACKPORT"||echo"diff command exited with $?">&2
39+
40+
set +x
41+
42+
printf"Approve the PR using gh? [y/N] "
43+
read -r r
44+
[ "$r"!="y" ] || {
45+
set -x
46+
gh pr review "$BACKPORT_PR" --approve
47+
}

0 commit comments

Comments
 (0)