link PR validation#112
Merged
Merged
Conversation
The `link` command previously allowed PRs in any state to be added to a
stack, including PRs that had already been merged, were closed, were
sitting in a merge queue, or had auto-merge enabled. Adding such PRs to
a stack is invalid because they have already been or will soon be merged,
which breaks the stacked PR workflow.
Add a new validation phase (Phase 2b) to `runLink` that checks the
eligibility of every existing PR found during lookup, before any new PRs
are created or stack operations are performed. Only open/draft PRs
without auto-merge enabled are eligible. All ineligible PRs are reported
at once with a clear per-PR error message indicating the specific reason
(merged, closed, in merge queue, or auto-merge enabled).
Changes:
internal/github/github.go:
- Add AutoMergeRequest struct and field on PullRequest
- Add IsAutoMergeEnabled() method on *PullRequest
- Update FindPRByNumber and FindPRForBranch GraphQL queries to fetch
the autoMergeRequest field
internal/github/github_test.go:
- Add TestPullRequest_IsAutoMergeEnabled (nil, non-nil, nil receiver)
cmd/link.go:
- Add pr field to resolvedArg to retain full PR data from lookup
- Add validatePREligibility() that rejects merged/closed/queued/
auto-merge-enabled PRs with descriptive error messages
- Wire validation into runLink between PR lookup and stack operations
cmd/link_test.go:
- Add 7 tests covering each disallowed state by PR number and branch
name, plus a multi-invalid-PR reporting test
Contributor
There was a problem hiding this comment.
Pull request overview
Adds an early validation step to gh stack link so that existing PRs resolved from CLI arguments must be eligible for stacking (not merged/closed, not in merge queue, and not auto-merge enabled), preventing invalid stacks from being created/updated.
Changes:
- Extend GitHub PR GraphQL models/queries to fetch
autoMergeRequest, and addIsAutoMergeEnabled()helper. - Add Phase 2b validation in
runLinkto reject ineligible resolved PRs and report all issues at once. - Add unit tests for auto-merge detection and for each ineligible PR state (by PR number and by branch), including multi-error reporting.
Show a summary per file
| File | Description |
|---|---|
| internal/github/github.go | Fetches autoMergeRequest via GraphQL and exposes IsAutoMergeEnabled() on PullRequest. |
| internal/github/github_test.go | Adds focused unit coverage for PullRequest.IsAutoMergeEnabled() behavior. |
| cmd/link.go | Stores full PR data for resolved args and validates PR eligibility before any stack operations. |
| cmd/link_test.go | Adds link command tests ensuring ineligible PRs are rejected early and reported clearly. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 4/4 changed files
- Comments generated: 0
ktravers
approved these changes
Jun 1, 2026
ktravers
left a comment
There was a problem hiding this comment.
Appreciate the clear feedback for invalid PRs 🚀
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.
The
linkcommand previously allowed PRs in any state to be added to a stack, including PRs that had already been merged, were closed, were sitting in a merge queue, or had auto-merge enabled. Adding such PRs to a stack is invalid because they have already been or will soon be merged, which breaks the stacked PR workflow.Add a new validation phase (Phase 2b) to
runLinkthat checks the eligibility of every existing PR found during lookup, before any new PRs are created or stack operations are performed. Only open/draft PRs without auto-merge enabled are eligible. All ineligible PRs are reported at once with a clear per-PR error message indicating the specific reason (merged, closed, in merge queue, or auto-merge enabled).Changes:
internal/github/github.go:
internal/github/github_test.go:
cmd/link.go:
cmd/link_test.go: