Skip to content

Commit 38c2b92

Browse files
authored
tools: add support for URLs to PR commits in merge.sh
PR-URL: #59162 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Moshe Atlow <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]>
1 parent 0938211 commit 38c2b92

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

tools/actions/merge.sh

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,46 @@
66
# To land a PR with this tool:
77
# 1. Run `git node land <pr-id-or-url> --fixupAll`
88
# 2. Copy the hash of the commit at the top of the PR branch.
9-
# 3. Run `tools/actions/merge.sh <pr-id-or-url> <commit-hash>`.
9+
# 3. Run `tools/actions/merge.sh <pr-id-or-url> <commit-hash>` or `tools/actions/merge.sh <url-to-PR-commit>`.
1010

1111
set -xe
1212

1313
pr=$1
1414
commit_head=$2
15-
shift 2 || { echo "Expected two arguments"; exit 1; }
1615

1716
OWNER=nodejs
1817
REPOSITORY=node
1918

2019
if expr "X$pr" : 'Xhttps://github.com/[^/]\{1,\}/[^/]\{1,\}/pull/[0-9]\{1,\}' >/dev/null; then
2120
OWNER="$(echo "$pr" | awk 'BEGIN { FS = "/" } ; { print $4 }')"
2221
REPOSITORY="$(echo "$pr" | awk 'BEGIN { FS = "/" } ; { print $5 }')"
22+
[ -n "$commit_head" ] || commit_head="$(echo "$pr" | awk 'BEGIN { FS = "/" } ; { print $9 }')"
2323
pr="$(echo "$pr" | awk 'BEGIN { FS = "/" } ; { print $7 }')"
24-
elif ! expr "X$pr" : 'X[0-9]\{1,\}' >/dev/null; then
25-
echo "The first argument should be the PR ID or URL"
2624
fi
2725

26+
validation_error=
27+
if ! expr "X${pr}X" : 'X[0-9]\{1,\}X' >/dev/null; then
28+
set +x
29+
echo "Invalid PR ID: $pr"
30+
validation_error=1
31+
fi
32+
if ! expr "X${commit_head}X" : 'X[a-f0-9]\{40\}X' >/dev/null; then
33+
set +x
34+
echo "Invalid PR head: $commit_head"
35+
validation_error=1
36+
fi
37+
[ -z "$validation_error" ] || {
38+
echo 'Usage:'
39+
printf '\t%s <pr-id-or-url> <commit-hash>\n' "$0"
40+
echo 'or:'
41+
printf '\t%s <url-to-PR-commit>\n' "$0"
42+
echo 'Examples:'
43+
printf '\t%s 12345 aaaaabbbbbcccccdddddeeeeefffff1111122222\n' "$0"
44+
printf '\t%s https://github.com/%s/pull/12345 aaaaabbbbbcccccdddddeeeeefffff1111122222\n' "$0" "$OWNER/$REPOSITORY"
45+
printf '\t%s https://github.com/%s/pull/12345/commits/aaaaabbbbbcccccdddddeeeeefffff1111122222\n' "$0" "$OWNER/$REPOSITORY"
46+
exit 1
47+
}
48+
2849
git log -1 HEAD --pretty='format:%B' | git interpret-trailers --parse --no-divider | \
2950
grep -q -x "^PR-URL: https://github.com/$OWNER/$REPOSITORY/pull/$pr$" || {
3051
echo "Invalid PR-URL trailer"

0 commit comments

Comments
 (0)