Skip to content

link PR validation#112

Merged
skarim merged 1 commit into
mainfrom
skarim/link-pr-conditions
Jun 1, 2026
Merged

link PR validation#112
skarim merged 1 commit into
mainfrom
skarim/link-pr-conditions

Conversation

@skarim
Copy link
Copy Markdown
Collaborator

@skarim skarim commented Jun 1, 2026

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

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
Copilot AI review requested due to automatic review settings June 1, 2026 15:59
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 add IsAutoMergeEnabled() helper.
  • Add Phase 2b validation in runLink to 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

Copy link
Copy Markdown

@ktravers ktravers left a comment

Choose a reason for hiding this comment

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

Appreciate the clear feedback for invalid PRs 🚀

@skarim skarim merged commit d2a390f into main Jun 1, 2026
7 checks passed
@skarim skarim deleted the skarim/link-pr-conditions branch June 1, 2026 22:54
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