From 188dce4f950214b549ed24bcc9c25d4a5c639499 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Fri, 3 Apr 2026 11:52:26 +0200 Subject: [PATCH 1/2] tools: improve backport review script Signed-off-by: Antoine du Hamel --- tools/actions/review_backport.sh | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/tools/actions/review_backport.sh b/tools/actions/review_backport.sh index 29dcc699235d23..56012568b27759 100755 --- a/tools/actions/review_backport.sh +++ b/tools/actions/review_backport.sh @@ -2,11 +2,16 @@ BACKPORT_PR=$1 +[ -x "$(command -v gh)" ] || { + # shellcheck disable=SC2016 + echo 'Missing required `gh` dependency' >&2 + exit 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." + echo "Usage:" >&2 + echo 'tools/actions/review_backport.sh https://github.com/nodejs/node/pull/ | less' >&2 + echo 'DIFF_CMD="codium --wait --diff" tools/actions/review_backport.sh https://github.com/nodejs/node/pull/' >&2 + echo "Limitations: This tools only supports PRs that landed as single commit, e.g. with 'commit-queue-squash' label." >&2 exit 1 } @@ -15,16 +20,28 @@ SED_CMD='s/^index [a-f0-9]\+..[a-f0-9]\+ \([0-7]\{6\}\)$/index eeeeeeeeee..eeeee set -ex +BACKPORT_PR_URL=$(gh pr view "$BACKPORT_PR" --json url --jq .url) + ORIGINAL=$(mktemp) BACKPORT=$(mktemp) +trap 'set -x; rm -f "$ORIGINAL" "$BACKPORT"; set +x; trap - EXIT; exit' EXIT INT HUP + 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" + curl -fsL "$BACKPORT_PR_URL/commits/$COMMIT_SHA.diff" | sed "$SED_CMD" >> "$BACKPORT" done -${DIFF_CMD:-diff} "$ORIGINAL" "$BACKPORT" -rm "$ORIGINAL" "$BACKPORT" +${DIFF_CMD:-diff} "$ORIGINAL" "$BACKPORT" || echo "diff command exited with $?" >&2 + +set +x + +printf "Approve the PR using gh? [y/N] " +read -r r +[ "$r" != "y" ] || { + set -x + gh pr review "$BACKPORT_PR" --approve +} From 3790b50e6567554cae54104cbf9b34cb33564887 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Fri, 3 Apr 2026 14:59:33 +0200 Subject: [PATCH 2/2] fixup! tools: improve backport review script --- tools/actions/review_backport.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/actions/review_backport.sh b/tools/actions/review_backport.sh index 56012568b27759..57b46c799e6404 100755 --- a/tools/actions/review_backport.sh +++ b/tools/actions/review_backport.sh @@ -2,7 +2,7 @@ BACKPORT_PR=$1 -[ -x "$(command -v gh)" ] || { +[ -x "$(command -v gh || true)" ] || { # shellcheck disable=SC2016 echo 'Missing required `gh` dependency' >&2 exit 1