Skip to content

Commit 19d633f

Browse files
aduh95targos
authored andcommitted
tools: add script to make reviewing backport PRs easier
PR-URL: #59161 Reviewed-By: Moshe Atlow <[email protected]>
1 parent b1d2878 commit 19d633f

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

tools/actions/review_backport.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/sh
2+
3+
BACKPORT_PR=$1
4+
5+
[ -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."
10+
11+
exit 1
12+
}
13+
14+
SED_CMD='s/^index [a-f0-9]\+..[a-f0-9]\+ \([0-7]\{6\}\)$/index eeeeeeeeee..eeeeeeeeee \1/g;s/^@@ -[0-9]\+,[0-9]\+ +[0-9]\+,[0-9]\+ @@/@@ -111,1 +111,1 @@/'
15+
16+
set -ex
17+
18+
ORIGINAL=$(mktemp)
19+
BACKPORT=$(mktemp)
20+
gh pr view "$BACKPORT_PR" --json commits --jq '.[] | map([ .oid, (.messageBody | match("(?:^|\\n)PR-URL: (https?://.+/pull/\\d+)(?:\\n|$)", "g") | .captures | last | .string)] | @tsv) | .[]' \
21+
| while read -r LINE; do
22+
COMMIT_SHA=$(echo "$LINE" | cut -f1)
23+
PR_URL=$(echo "$LINE" | cut -f2)
24+
25+
curl -fsL "$PR_URL.diff" | sed "$SED_CMD" >> "$ORIGINAL"
26+
curl -fsL "$BACKPORT_PR/commits/$COMMIT_SHA.diff" | sed "$SED_CMD" >> "$BACKPORT"
27+
done
28+
29+
${DIFF_CMD:-diff} "$ORIGINAL" "$BACKPORT"
30+
rm "$ORIGINAL" "$BACKPORT"

0 commit comments

Comments
 (0)