Skip to content

[SPARK-56963][INFRA] Auto-close non-default-branch PRs in merge_spark_pr.py#56007

Closed
zhengruifeng wants to merge 3 commits into
apache:masterfrom
zhengruifeng:merge-script-close-backport-pr
Closed

[SPARK-56963][INFRA] Auto-close non-default-branch PRs in merge_spark_pr.py#56007
zhengruifeng wants to merge 3 commits into
apache:masterfrom
zhengruifeng:merge-script-close-backport-pr

Conversation

@zhengruifeng
Copy link
Copy Markdown
Contributor

@zhengruifeng zhengruifeng commented May 20, 2026

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)

### 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)
@zhengruifeng zhengruifeng changed the title [INFRA] Auto-close non-default-branch PRs in merge_spark_pr.py [SPARK-56963][INFRA] Auto-close non-default-branch PRs in merge_spark_pr.py May 20, 2026
@zhengruifeng zhengruifeng marked this pull request as ready for review May 20, 2026 08:40
…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)
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>
@zhengruifeng
Copy link
Copy Markdown
Contributor Author

thanks, merged into mater/4.x with the updated merge script

@zhengruifeng zhengruifeng deleted the merge-script-close-backport-pr branch May 20, 2026 10:46
Copy link
Copy Markdown
Member

@dongjoon-hyun dongjoon-hyun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, @zhengruifeng and @yaooqinn .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants