| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2,11 +2,16 @@ | |||
| 2 | 2 | ||
| 3 | 3 | BACKPORT_PR=$1 | |
| 4 | 4 | ||
| 5 | + [ -x "$(command -v gh || true)" ] || { | ||
| 6 | + # shellcheck disable=SC2016 | ||
| 7 | + echo 'Missing required `gh` dependency' >&2 | ||
| 8 | + exit 1 | ||
| 9 | + } | ||
| 5 | 10 | [ -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 | ||
| 10 | 15 | ||
| 11 | 16 | exit 1 | |
| 12 | 17 | } | |
@@ -15,16 +20,28 @@ SED_CMD='s/^index [a-f0-9]\+..[a-f0-9]\+ \([0-7]\{6\}\)$/index eeeeeeeeee..eeeee | |||
| 15 | 20 | ||
| 16 | 21 | set -ex | |
| 17 | 22 | ||
| 23 | + BACKPORT_PR_URL=$(gh pr view "$BACKPORT_PR" --json url --jq .url) | ||
| 24 | + | ||
| 18 | 25 | ORIGINAL=$(mktemp) | |
| 19 | 26 | BACKPORT=$(mktemp) | |
| 27 | + trap 'set -x; rm -f "$ORIGINAL" "$BACKPORT"; set +x; trap - EXIT; exit' EXIT INT HUP | ||
| 28 | + | ||
| 20 | 29 | 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 | 30 | | while read -r LINE; do | |
| 22 | 31 | COMMIT_SHA=$(echo "$LINE" | cut -f1) | |
| 23 | 32 | PR_URL=$(echo "$LINE" | cut -f2) | |
| 24 | 33 | ||
| 25 | 34 | 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" | ||
| 27 | 36 | done | |
| 28 | 37 | ||
| 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 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments