From be77b37d3fa2157386464e9b3c364f66304fc8e2 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Tue, 22 Jul 2025 11:24:11 +0200 Subject: [PATCH 1/4] tools: add support for URLs to PR commits in `merge.sh` --- tools/actions/merge.sh | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/tools/actions/merge.sh b/tools/actions/merge.sh index 35d1e033501ba4..1e2759cee25816 100755 --- a/tools/actions/merge.sh +++ b/tools/actions/merge.sh @@ -6,13 +6,12 @@ # To land a PR with this tool: # 1. Run `git node land --fixupAll` # 2. Copy the hash of the commit at the top of the PR branch. -# 3. Run `tools/actions/merge.sh `. +# 3. Run `tools/actions/merge.sh ` or `tools/actions/merge.sh `. set -xe pr=$1 commit_head=$2 -shift 2 || { echo "Expected two arguments"; exit 1; } OWNER=nodejs REPOSITORY=node @@ -20,11 +19,33 @@ REPOSITORY=node if expr "X$pr" : 'Xhttps://github.com/[^/]\{1,\}/[^/]\{1,\}/pull/[0-9]\{1,\}' >/dev/null; then OWNER="$(echo "$pr" | awk 'BEGIN { FS = "/" } ; { print $4 }')" REPOSITORY="$(echo "$pr" | awk 'BEGIN { FS = "/" } ; { print $5 }')" + [ -n "$commit_head" ] || commit_head="$(echo "$pr" | awk 'BEGIN { FS = "/" } ; { print $9 }')" pr="$(echo "$pr" | awk 'BEGIN { FS = "/" } ; { print $7 }')" -elif ! expr "X$pr" : 'X[0-9]\{1,\}' >/dev/null; then - echo "The first argument should be the PR ID or URL" fi +validation_error= +if ! expr "X$pr" : 'X[0-9]\{1,\}' >/dev/null; then + set +x + echo "Invalid PR ID: $pr" + validation_error=1 +fi +if ! expr "X$commit_head" : 'X[a-f0-9]\{40\}' >/dev/null; then + set +x + echo "Invalid PR head: $commit_head" + validation_error=1 +fi +[ -z "$validation_error" ] || { + echo 'Usage:' + echo "\t$0 " + echo 'or:' + echo "\t$0 " + echo 'Examples:' + echo "\t$0 12345 aaaaabbbbbcccccdddddeeeeefffff1111122222" + echo "\t$0 https://github.com/$OWNER/$REPOSITORY/pull/12345 aaaaabbbbbcccccdddddeeeeefffff1111122222" + echo "\t$0 https://github.com/$OWNER/$REPOSITORY/pull/12345/commit/aaaaabbbbbcccccdddddeeeeefffff1111122222" + exit 1 +} + git log -1 HEAD --pretty='format:%B' | git interpret-trailers --parse --no-divider | \ grep -q -x "^PR-URL: https://github.com/$OWNER/$REPOSITORY/pull/$pr$" || { echo "Invalid PR-URL trailer" From 3dc1eb378242b81b3b8d22dbce135b61d016c432 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Tue, 22 Jul 2025 14:34:49 +0200 Subject: [PATCH 2/4] fixup! tools: add support for URLs to PR commits in `merge.sh` --- tools/actions/merge.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tools/actions/merge.sh b/tools/actions/merge.sh index 1e2759cee25816..099a74ca1277e8 100755 --- a/tools/actions/merge.sh +++ b/tools/actions/merge.sh @@ -36,13 +36,13 @@ if ! expr "X$commit_head" : 'X[a-f0-9]\{40\}' >/dev/null; then fi [ -z "$validation_error" ] || { echo 'Usage:' - echo "\t$0 " + printf '\t%s \n' "$0" echo 'or:' - echo "\t$0 " + printf '\t%s \n' "$0" echo 'Examples:' - echo "\t$0 12345 aaaaabbbbbcccccdddddeeeeefffff1111122222" - echo "\t$0 https://github.com/$OWNER/$REPOSITORY/pull/12345 aaaaabbbbbcccccdddddeeeeefffff1111122222" - echo "\t$0 https://github.com/$OWNER/$REPOSITORY/pull/12345/commit/aaaaabbbbbcccccdddddeeeeefffff1111122222" + printf '\t%s 12345 aaaaabbbbbcccccdddddeeeeefffff1111122222\n' "$0" + printf '\t%s https://github.com/%s/pull/12345 aaaaabbbbbcccccdddddeeeeefffff1111122222\n' "$0" "$OWNER/$REPOSITORY" + printf '\t%s https://github.com/%s/pull/12345/commit/aaaaabbbbbcccccdddddeeeeefffff1111122222\n' "$0" "$OWNER/$REPOSITORY" exit 1 } From dab997edfa22657bc7335ce3f2f007f627efb849 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Tue, 22 Jul 2025 14:38:02 +0200 Subject: [PATCH 3/4] fixup! tools: add support for URLs to PR commits in `merge.sh` --- tools/actions/merge.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/actions/merge.sh b/tools/actions/merge.sh index 099a74ca1277e8..93be06b47296c9 100755 --- a/tools/actions/merge.sh +++ b/tools/actions/merge.sh @@ -24,12 +24,12 @@ if expr "X$pr" : 'Xhttps://github.com/[^/]\{1,\}/[^/]\{1,\}/pull/[0-9]\{1,\}' >/ fi validation_error= -if ! expr "X$pr" : 'X[0-9]\{1,\}' >/dev/null; then +if ! expr "X${pr}X" : 'X[0-9]\{1,\}X' >/dev/null; then set +x echo "Invalid PR ID: $pr" validation_error=1 fi -if ! expr "X$commit_head" : 'X[a-f0-9]\{40\}' >/dev/null; then +if ! expr "X${commit_head}X" : 'X[a-f0-9]\{40\}X' >/dev/null; then set +x echo "Invalid PR head: $commit_head" validation_error=1 From 97e62c757a833b0da61bb3b968f2789a335a94c0 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Tue, 22 Jul 2025 15:49:17 +0200 Subject: [PATCH 4/4] Update tools/actions/merge.sh --- tools/actions/merge.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/actions/merge.sh b/tools/actions/merge.sh index 93be06b47296c9..45947f64c2a4db 100755 --- a/tools/actions/merge.sh +++ b/tools/actions/merge.sh @@ -42,7 +42,7 @@ fi echo 'Examples:' printf '\t%s 12345 aaaaabbbbbcccccdddddeeeeefffff1111122222\n' "$0" printf '\t%s https://github.com/%s/pull/12345 aaaaabbbbbcccccdddddeeeeefffff1111122222\n' "$0" "$OWNER/$REPOSITORY" - printf '\t%s https://github.com/%s/pull/12345/commit/aaaaabbbbbcccccdddddeeeeefffff1111122222\n' "$0" "$OWNER/$REPOSITORY" + printf '\t%s https://github.com/%s/pull/12345/commits/aaaaabbbbbcccccdddddeeeeefffff1111122222\n' "$0" "$OWNER/$REPOSITORY" exit 1 }