-
-
Notifications
You must be signed in to change notification settings - Fork 34.3k
tools: add util scripts to land and rebase PRs #54656
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
9cf01c0
tools: add util scripts to land and rebase PRs
aduh95 8b27b0e
fixup! tools: add util scripts to land and rebase PRs
aduh95 720f53f
Apply suggestions from code review
aduh95 39f5dea
remove `commit_queue_failed`
aduh95 cf05d2a
Update tools/actions/merge.sh
aduh95 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| #!/bin/sh | ||
|
|
||
| # Requires [gh](https://cli.github.com/), [jq](https://jqlang.github.io), git, and grep. Also awk if you pass a URL. | ||
|
|
||
| # This script can be used to "purple-merge" PRs that are supposed to land as a single commit, using the "Squash and Merge" feature of GitHub. | ||
| # To land a PR with this tool: | ||
| # 1. Run `git node land <pr-id-or-url> --fixupAll` | ||
| # 2. Copy the hash of the commit at the top of the PR branch. | ||
| # 3. Run `tools/actions/merge.sh <pr-id-or-url> <commit-hash>`. | ||
|
|
||
| set -xe | ||
|
|
||
| pr=$1 | ||
| commit_head=$2 | ||
| shift 2 || { echo "Expected two arguments"; exit 1; } | ||
|
|
||
| OWNER=nodejs | ||
| 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 }')" | ||
| 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 | ||
|
|
||
| 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" | ||
| 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 "Refuse to squash and merge a PR landing in more than one commit" | ||
| exit 1 | ||
| } | ||
|
|
||
| commit_title=$(git log -1 --pretty='format:%s') | ||
| commit_body=$(git log -1 --pretty='format:%b') | ||
|
|
||
| jq -n \ | ||
| --arg title "${commit_title}" \ | ||
| --arg body "${commit_body}" \ | ||
| --arg head "${commit_head}" \ | ||
| '{merge_method:"squash",commit_title:$title,commit_message:$body,sha:$head}' > output.json | ||
| cat output.json | ||
| if ! gh api -X PUT "repos/${OWNER}/${REPOSITORY}/pulls/${pr}/merge" --input output.json > output; then | ||
| cat output | ||
| echo "Failed to merge $pr" | ||
| rm output output.json | ||
| exit 1 | ||
| fi | ||
| cat output | ||
| if ! commits="$(jq -r 'if .merged then .sha else error("not merged") end' < output)"; then | ||
| echo "Failed to merge $pr" | ||
| rm output output.json | ||
| exit 1 | ||
| fi | ||
| rm output.json output | ||
|
|
||
| gh pr comment "$pr" --body "Landed in $commits" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| #!/bin/sh | ||
|
|
||
| set -xe | ||
|
|
||
| # shellcheck disable=SC2016 | ||
| gh api graphql -F "prID=$(gh pr view "$1" --json id --jq .id || true)" -f query=' | ||
| mutation RebasePR($prID: ID!) { | ||
| updatePullRequestBranch(input:{pullRequestId:$prID,updateMethod:REBASE}) { | ||
| clientMutationId | ||
| } | ||
| }' |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.