[SPARK-56963][INFRA] Auto-close non-default-branch PRs in merge_spark_pr.py#56007
Closed
zhengruifeng wants to merge 3 commits into
Closed
[SPARK-56963][INFRA] Auto-close non-default-branch PRs in merge_spark_pr.py#56007zhengruifeng wants to merge 3 commits into
zhengruifeng wants to merge 3 commits into
Conversation
### What changes were proposed in this pull request?
When `dev/merge_spark_pr.py` merges a PR whose target branch is not the
repository's default (e.g. backport PRs against `branch-X.Y`),
explicitly close the PR through the GitHub REST API after the push
succeeds. Specifically:
- Add a small `close_pr(pr_num)` helper that issues an authenticated
`PATCH /pulls/{n}` with `{"state": "closed"}`.
- Plumb a `default_branch` parameter into `merge_pr()`. `main()`
fetches it via `GET /repos/apache/spark` once and passes it in.
- After a successful `git push` in `merge_pr()`, if
`target_ref != default_branch`, call `close_pr(pr_num)`.
### Why are the changes needed?
The squash-merge commit message already contains `Closes #N from ...`,
which GitHub treats as a closing keyword. However, GitHub honors
closing keywords **only when the commit lands on the repository's
default branch**. Backport PRs that target `branch-X.Y` therefore got
merged successfully but stayed open on GitHub, and the committer had
to close them manually. PR apache#56004 was a recent example.
### Does this PR introduce _any_ user-facing change?
No.
### How was this patch tested?
Compile-checked with `python3 -m py_compile dev/merge_spark_pr.py` and
the existing doctests still pass via
`python3 -m doctest dev/merge_spark_pr.py`. End-to-end merge behavior
will be validated the next time a committer runs the script on a
backport PR.
### Was this patch authored or co-authored using generative AI tooling?
Generated-by: Claude Code (Claude Opus 4.7)
…branch
Replace the `target_ref != default_branch` guard with a direct
`get_json("/pulls/N")["state"] != "closed"` check after the push.
This drops the extra `default_branch` parameter on `merge_pr()` and
the `GET /repos/apache/spark` fetch in `main()`, and is self-correcting
for any edge case where GitHub's auto-close does not fire.
Generated-by: Claude Code (Claude Opus 4.7)
merge_pr() now stops at "Pull request merged!" again. The state-check + close_pr() call moves to main(), right after the merge_pr() call returns, which keeps merge_pr() focused on the local-merge+push mechanics and surfaces the close behavior at the top level where the JIRA / cherry-pick prompts also live. Generated-by: Claude Code (Claude Opus 4.7)
yaooqinn
approved these changes
May 20, 2026
zhengruifeng
added a commit
that referenced
this pull request
May 20, 2026
…_pr.py
### What changes were proposed in this pull request?
When `dev/merge_spark_pr.py` merges a PR whose target branch is not the repository's default (e.g. backport PRs against `branch-X.Y`), explicitly close the PR through the GitHub REST API after the push. Specifically:
- Add a small `close_pr(pr_num)` helper that issues an authenticated `PATCH /pulls/{n}` with `{"state": "closed"}`.
- After a successful `git push` in `merge_pr()`, fetch the PR via `GET /pulls/{n}` and, if the state is still `"open"`, call `close_pr(pr_num)`.
### Why are the changes needed?
The squash-merge commit message already contains `Closes #N from ...`, which GitHub treats as a closing keyword. However, GitHub honors closing keywords **only when the commit lands on the repository's default branch**. Backport PRs that target `branch-X.Y` therefore got merged successfully but stayed open on GitHub, and the committer had to close them manually. #56004 was a recent example.
Checking the PR state after the push (instead of comparing `target_ref` to the default branch up front) keeps the change small and self-correcting: it does the right thing whenever GitHub's auto-close did not fire, without having to encode the default-branch rule in the script.
### Does this PR introduce _any_ user-facing change?
No.
### How was this patch tested?
Compile-checked with `python3 -m py_compile dev/merge_spark_pr.py` and the existing doctests still pass via `python3 -m doctest dev/merge_spark_pr.py`. End-to-end merge behavior will be validated the next time a committer runs the script on a backport PR.
### Was this patch authored or co-authored using generative AI tooling?
Generated-by: Claude Code (Claude Opus 4.7)
Closes #56007 from zhengruifeng/merge-script-close-backport-pr.
Authored-by: Ruifeng Zheng <ruifengz@apache.org>
Signed-off-by: Ruifeng Zheng <ruifengz@foxmail.com>
(cherry picked from commit 4988ef1)
Signed-off-by: Ruifeng Zheng <ruifengz@foxmail.com>
Contributor
Author
|
thanks, merged into mater/4.x with the updated merge script |
Member
dongjoon-hyun
left a comment
There was a problem hiding this comment.
Thank you, @zhengruifeng and @yaooqinn .
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What changes were proposed in this pull request?
When
dev/merge_spark_pr.pymerges a PR whose target branch is not the repository's default (e.g. backport PRs againstbranch-X.Y), explicitly close the PR through the GitHub REST API after the push. Specifically:close_pr(pr_num)helper that issues an authenticatedPATCH /pulls/{n}with{"state": "closed"}.git pushinmerge_pr(), fetch the PR viaGET /pulls/{n}and, if the state is still"open", callclose_pr(pr_num).Why are the changes needed?
The squash-merge commit message already contains
Closes #N from ..., which GitHub treats as a closing keyword. However, GitHub honors closing keywords only when the commit lands on the repository's default branch. Backport PRs that targetbranch-X.Ytherefore got merged successfully but stayed open on GitHub, and the committer had to close them manually. #56004 was a recent example.Checking the PR state after the push (instead of comparing
target_refto the default branch up front) keeps the change small and self-correcting: it does the right thing whenever GitHub's auto-close did not fire, without having to encode the default-branch rule in the script.Does this PR introduce any user-facing change?
No.
How was this patch tested?
Compile-checked with
python3 -m py_compile dev/merge_spark_pr.pyand the existing doctests still pass viapython3 -m doctest dev/merge_spark_pr.py. End-to-end merge behavior will be validated the next time a committer runs the script on a backport PR.Was this patch authored or co-authored using generative AI tooling?
Generated-by: Claude Code (Claude Opus 4.7)