Skip to content

Unstack Updates: preflight PR eligibility before delete and improve API errors#136

Open
wiseemily88 wants to merge 3 commits into
mainfrom
update_unstack_to_block_all_locked_unstacking
Open

Unstack Updates: preflight PR eligibility before delete and improve API errors#136
wiseemily88 wants to merge 3 commits into
mainfrom
update_unstack_to_block_all_locked_unstacking

Conversation

@wiseemily88

@wiseemily88 wiseemily88 commented Jun 17, 2026

Copy link
Copy Markdown

part of https://github.com/github/pull-requests/issues/24519
related to api changes here: https://github.com/github/github/pull/436056/overview

This pull request enhances the safety and robustness of the unstack command by adding a preflight check to prevent unstacking when all associated pull requests (PRs) are ineligible (e.g., merged, queued for merge, or have auto-merge enabled). It also improves error handling and test coverage for these scenarios. Includes enhanced error messages for failed preflight checks and for specific HTTP errors (such as 422) returned by the GitHub API during stack deletion, providing clearer feedback to the user.

…s.Block unstack delete only when all PRs in the stack are ineligible
@wiseemily88 wiseemily88 requested a review from skarim as a code owner June 17, 2026 21:07
Copilot AI review requested due to automatic review settings June 17, 2026 21:07
GitHub Advanced Security started work on behalf of wiseemily88 June 17, 2026 21:07 View session
GitHub Advanced Security finished work on behalf of wiseemily88 June 17, 2026 21:09

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.

Pull request overview

This PR enhances the unstack command's safety by adding a preflight check that prevents stack deletion when all associated pull requests are ineligible (merged, queued for merge, or have auto-merge enabled). It also adds handling for HTTP 422 errors from the GitHub API during stack deletion, providing clearer feedback to the user. The changes are well-tested with four new test cases covering the blocking, mixed eligibility, API failure, and 422 error scenarios.

Changes:

  • Added shouldBlockUnstackDelete preflight function that checks PR eligibility before attempting to delete a stack on GitHub, blocking only when all PRs are ineligible
  • Added specific handling for HTTP 422 responses from DeleteStack, surfacing the API error message
  • Updated existing tests and added new test cases covering preflight blocking, mixed eligibility, API lookup failures, and 422 error handling
Show a summary per file
File Description
cmd/unstack.go Added shouldBlockUnstackDelete function with PR eligibility logic, integrated preflight call before DeleteStack, and added 422 HTTP error handling
cmd/unstack_test.go Added four new test cases for preflight scenarios and updated existing tests to include PullRequestRef fields to accommodate the new preflight check

Copilot's findings

  • Files reviewed: 2/2 changed files
  • Comments generated: 1

Comment thread cmd/unstack.go Outdated

@skarim skarim left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

One minor comment, otherwise looks good! 💯

Comment thread cmd/unstack.go Outdated
Co-authored-by: Sameen Karim <skarim@github.com>
GitHub Advanced Security started work on behalf of wiseemily88 June 17, 2026 21:28 View session
GitHub Advanced Security finished work on behalf of wiseemily88 June 17, 2026 21:29
Comment thread cmd/unstack.go
Comment thread cmd/unstack.go
GitHub Advanced Security started work on behalf of wiseemily88 June 18, 2026 04:06 View session
GitHub Advanced Security finished work on behalf of wiseemily88 June 18, 2026 04:07
@wiseemily88 wiseemily88 requested a review from francisfuzz June 18, 2026 04:08

@francisfuzz francisfuzz 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.

✅ !

To confirm: we'll need https://github.com/github/github/pull/436056 to land first, before merging this in -- 👍🏽 ?

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.

4 participants