Migrate to new Stacks REST API#177
Open
skarim wants to merge 4 commits into
Open
Conversation
The new Stacks REST API exposes a human-facing stack number (shown in the github.com UI) alongside the internal stack id. Add a Number field to the stack.Stack model and document it in schema.json so it can be persisted in the .git/gh-stack file. Purely additive; behavior is unchanged until callers populate it. Copilot-Session: 03673c26-a245-42da-93ed-dfcebc92a740
Replace the private cli_internal stack endpoints with the new public
Stacks REST API (/repos/{owner}/{repo}/stacks):
- ListStacks / FindStackForPR (?pull_request= filter) / GetStack for reads
- CreateStack, which now returns the created stack including its number
- AddToStack for delta-only appends (there is no full-replace endpoint)
- Unstack for server-driven removal (204 dissolved / 200 partial / 422)
Migrate all callers (checkout, submit, link, sync, unstack, utils) and
drop the client-side unstack eligibility pre-check — the server now
decides which PRs can be unstacked. checkout discovers stacks via the
pull_request filter; submit/link express updates as append-only deltas;
unstack adopts partial-unstack semantics, keeping local tracking when
PRs remain stacked on GitHub.
RemoteStack now carries the stack number, and stack updates resolve a
stack's number from its internal id for stack files that predate the
Number field.
Copilot-Session: 03673c26-a245-42da-93ed-dfcebc92a740
The new Stacks REST API is public, so any user authenticated with the GitHub CLI (including via a PAT with repo scope) can perform stack operations once the feature is enabled for their repository. Remove the PAT detection and the private-preview gating: - Delete Config.WarnIfPAT / IsPersonalAccessToken and the TokenForHostFn test hook (internal/config/auth.go is no longer needed). - Drop the submit pre-flight that aborted on a PAT. - Rename warnStacksUnavailableOrPAT to warnStacksUnavailable and simplify it to the "stacked PRs not enabled" message. Copilot-Session: 03673c26-a245-42da-93ed-dfcebc92a740
Contributor
There was a problem hiding this comment.
Pull request overview
Migrates stack operations from temporary internal endpoints to the public Stacks REST API.
Changes:
- Adds stack numbers and public REST API client methods.
- Updates submit, link, checkout, sync, and unstack workflows.
- Removes PAT-specific restrictions and updates tests.
Show a summary per file
| File | Description |
|---|---|
internal/stack/stack.go |
Adds stack number storage. |
internal/stack/stack_test.go |
Tests number persistence. |
internal/stack/schema.json |
Documents the number field. |
internal/github/mock_client.go |
Updates stack API mocks. |
internal/github/github.go |
Implements public REST stack operations. |
internal/github/client_interface.go |
Updates the client interface. |
internal/config/config.go |
Removes the token test hook. |
internal/config/auth.go |
Removes PAT detection. |
internal/config/auth_test.go |
Removes PAT tests. |
cmd/utils.go |
Adds number resolution and reconciliation support. |
cmd/utils_test.go |
Updates warning tests. |
cmd/unstack.go |
Adopts server-driven unstacking. |
cmd/unstack_test.go |
Tests new unstack semantics. |
cmd/sync_test.go |
Updates sync API mocks and expectations. |
cmd/submit.go |
Implements append-only stack reconciliation. |
cmd/submit_test.go |
Updates submit and modify-recovery tests. |
cmd/link.go |
Uses delta-based stack additions. |
cmd/link_test.go |
Tests additive linking behavior. |
cmd/checkout.go |
Uses filtered discovery and stack numbers. |
cmd/checkout_test.go |
Updates remote checkout tests. |
Review details
- Files reviewed: 20/20 changed files
- Comments generated: 7
- Review effort level: Medium
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.
With the upcoming release of the public REST API for stacked pull requests (
/repos/{owner}/{repo}/stacks), this will replace the temporarycli_internalendpoints that gh-stack had previously been using. This moves every stack operation onto it. Because the API is public, it also lifts the auth restriction added in #113: anyone authenticated with the GitHub CLI can run stack operations once the feature is enabled for their repo — the OAuth-only limitation is gone.What the new API gives us
GET /stacks) with a server-side?pull_request=Nfilter to find the stack a PR belongs to.GET /stacks/{number}) — fetch a single stack by its number.POST /stacks) — returns the created stack, including its number.POST /stacks/{number}/add) — append PRs to the top of a stack (delta only; we no longer resend the full PR list).POST /stacks/{number}/unstack) — the server decides which PRs can be removed.Behavior changes worth noting
?pull_request=filter instead of listing every stack and scanning client-side.submitandlinkcompute the delta and append it. A desired change that isn't a clean append onto the remote stack — a reorder, or a removal such as merged PRs leaving the stack — is left untouched rather than force-rewritten.unstackis now server-driven. The old client-side eligibility pre-check is gone. The server removes the unlocked PRs and returns204when the stack is fully dissolved,200when some PRs (queued for merge or with auto-merge enabled) remain, or422when nothing can be removed.unstackkeeps local tracking when PRs remain on the stack.Changes
Add stack Number field to local model and schema
internal/stack/stack.go,schema.json— add theNumberfield to theStackmodel and document it. Additive only; nothing populates it yet.Cut over stack operations to the public Stacks REST API
internal/github/github.go— the core of the change. Point the client at the new/stacksendpoints and reworkRemoteStackto carry the stack'sid,number,base,openstate, and PR list. AddsFindStackForPR(the?pull_request=lookup),GetStack,AddToStack(delta append), and aUnstackthat distinguishes the204(dissolved) from200(PRs remain) responses.client_interface.goandmock_client.gofollow the new method set.cmd/submit.go,cmd/link.go— reconcile against the remote stack via the?pull_request=lookup and express updates as delta appends rather than resending the full list.cmd/checkout.go— discover a PR's stack throughFindStackForPRinstead of scanning every stack.cmd/unstack.go— drop the client-side eligibility pre-check and react to the server's204/200/422result, keeping local tracking when PRs remain.cmd/utils.go— shared helpers for thesyncreconcile path and for resolving a stack's number from its id.cmd/*_test.go— command tests updated for the new client surface and mock.Remove the personal access token (PAT) limitation
internal/config/auth.goandauth_test.go, and theTokenForHostFntest hook inconfig.go.cmd/submit.godrops the PAT pre-flight;cmd/utils.gorenameswarnStacksUnavailableOrPAT→warnStacksUnavailable, andcheckout.go/link.godrop the PAT-specific messaging. A 404 now simply means stacked PRs aren't enabled for the repo.Testing
unstacksemantics.204/200/422paths.go test -race ./...,go vet ./..., andgofmtare clean, and each of the three commits builds and passes tests independently.Stack created with GitHub Stacks CLI • Give Feedback 💬