diff --git a/tools/actions/review_backport.sh b/tools/actions/review_backport.sh new file mode 100755 index 00000000000000..29dcc699235d23 --- /dev/null +++ b/tools/actions/review_backport.sh @@ -0,0 +1,30 @@ +#!/bin/sh + +BACKPORT_PR=$1 + +[ -n "$BACKPORT_PR" ] || { + echo "Usage:" + echo 'tools/actions/review_backport.sh https://github.com/nodejs/node/pull/ | less' + echo 'DIFF_CMD="codium --wait --diff" tools/actions/review_backport.sh https://github.com/nodejs/node/pull/' + echo "Limitations: This tools only supports PRs that landed as single commit, e.g. with 'commit-queue-squash' label." + + exit 1 +} + +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 @@/' + +set -ex + +ORIGINAL=$(mktemp) +BACKPORT=$(mktemp) +gh pr view "$BACKPORT_PR" --json commits --jq '.[] | map([ .oid, (.messageBody | match("(?:^|\\n)PR-URL: (https?://.+/pull/\\d+)(?:\\n|$)", "g") | .captures | last | .string)] | @tsv) | .[]' \ +| while read -r LINE; do + COMMIT_SHA=$(echo "$LINE" | cut -f1) + PR_URL=$(echo "$LINE" | cut -f2) + + curl -fsL "$PR_URL.diff" | sed "$SED_CMD" >> "$ORIGINAL" + curl -fsL "$BACKPORT_PR/commits/$COMMIT_SHA.diff" | sed "$SED_CMD" >> "$BACKPORT" +done + +${DIFF_CMD:-diff} "$ORIGINAL" "$BACKPORT" +rm "$ORIGINAL" "$BACKPORT"