Skip to content

Add a hint to handle stacks that have closed pull requests - #612

Open
nickborromeo wants to merge 4 commits into
mainfrom
closed-bottom-pr-hint
Open

nickborromeo wants to merge 4 commits into
mainfrom
closed-bottom-pr-hint

Conversation

@nickborromeo

Copy link
Copy Markdown
Member

When a stack has a closed pull request, it is technically invalid and cannot be merged. This is not clear to the user. This change makes it so that we let the user know how to handle these cases by detecting closed pull requests in the stack when running the merge and sync commands.

Closed PR is the lowest unmerged layer:

⚠ PR #101 (b1) — Closed
✓ PR #102 (b2) — Open
âš  #101 is closed and blocks merging the stack
  Reopen #101, or run `gh stack modify` to drop it from the stack (or fold it to keep its changes), then run `gh stack submit` to recreate the stack on GitHub

Closed PR is higher up:

✓ PR #101 (b1) — Open
⚠ PR #102 (b2) — Closed
✓ PR #103 (b3) — Open
âš  #102 is closed and blocks merging it and the PRs above it; #101 can still be merged
  Reopen #102, or run `gh stack modify` to drop it to drop it from the stack (or fold it to keep its changes), then run `gh stack submit` to recreate the stack on GitHub

…ging

This adds a hintClosedBlocker helper that checks if the hint for closed
PRs should be displayed or not.

It then uses this helper in the merge path
As we scan through the sync'd prs; we let the user know if there are any
closed prs that could block the merging and allow them to handle it with
the hint.
Copilot AI max review requested due to automatic review settings November 3, 2026 06:08
@nickborromeo
nickborromeo requested a review from skarim as a code owner November 3, 2026 06:08

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Closed-PR blockers remain hidden in some merge and sync paths, while recovery guidance can target the wrong stack or fail for last-layer cases.

5 open issues
What changed in this PR

Adds closed-pull-request diagnostics and recovery guidance to gh stack’s merge and sync workflows, helping users understand which layers are blocked.

Changes:

  • Reports closed PRs during sync and identifies lower PRs that can still merge.
  • Adds shared reopen/modify/submit guidance to merge errors.
  • Adds regression tests and documents the recovery workflow.
File Description
README.md Documents closed-PR blockers and recovery commands.
docs/​src/​content/​docs/​reference/​cli.md Adds matching guidance to the CLI reference.
cmd/​utils.go Introduces the shared closed-PR recovery hint.
cmd/​sync.go Reports closed PRs and their effect on merging.
cmd/​sync_test.go Tests closed PRs at the bottom, middle, and top.
cmd/​merge.go Adds recovery hints to closed-PR merge errors.
cmd/​merge_test.go Tests closed targets and blockers, plus draft-hint exclusion.

Review effort: Max

Comment thread cmd/merge.go
top := candidates[len(candidates)-1].Number
cfg.Errorf("cannot merge the whole stack: pull request #%d is %s", blocker.Number, blockerState(blocker))
cfg.Printf("Merge up to #%d with `%s`", top, cfg.ColorAccent(fmt.Sprintf("gh stack merge %d", top)))
hintClosedBlocker(cfg, blocker)
Comment thread cmd/merge.go
Comment on lines 566 to +568
case pr.State == "closed":
cfg.Errorf("pull request #%d is closed", prNumber)
hintClosedBlocker(cfg, pr)
Comment thread cmd/sync.go
cfg.Printf("")
cfg.Printf("Syncing PRs ...")
_ = syncStackPRs(cfg, s)
prs := syncStackPRs(cfg, s)
Comment thread cmd/utils.go
Comment on lines +673 to +674
cfg.Printf(" Reopen #%d, or run `%s` to drop it from the stack (or fold it to keep its changes), then run `%s` to recreate the stack on GitHub",
number, cfg.ColorAccent("gh stack modify"), cfg.ColorAccent("gh stack submit"))
Comment thread cmd/utils.go
Comment on lines +673 to +674
cfg.Printf(" Reopen #%d, or run `%s` to drop it from the stack (or fold it to keep its changes), then run `%s` to recreate the stack on GitHub",
number, cfg.ColorAccent("gh stack modify"), cfg.ColorAccent("gh stack submit"))

This branch has not been deployed

No deployments
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.

2 participants