parse PR URLs in args#122
Open
skarim wants to merge 2 commits into
Open
Conversation
Add support for GitHub PR URLs (e.g. https://github.com/owner/repo/pull/42) as arguments to `gh stack link` and `gh stack checkout`, in addition to the existing PR number and branch name support. For `link`: PR URLs are parsed in findExistingPR before the numeric check. Unlike numeric args, if a URL-extracted PR number doesn't exist, the command errors immediately rather than falling through to branch name lookup (since a URL can never be a valid branch name). For `checkout`: PR URLs are parsed in runCheckout before the numeric check, routing to resolveNumericTarget which supports both local and remote API fallback — same behavior as passing a PR number directly. Closes #115 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR extends gh stack link and gh stack checkout to accept GitHub PR URLs (e.g., https://github.com/owner/repo/pull/42) in addition to PR numbers and branch names. It leverages the existing parsePRURL utility that was already used internally by other commands like switch and navigate, and wires it into the argument resolution logic of link and checkout.
Changes:
- Added PR URL parsing in
findExistingPR(link) andrunCheckout(checkout) that routes parsed URLs through the same resolution paths as numeric PR arguments - Added 5 new tests covering URL-based stack creation, not-found errors, mixed input, and both local and remote checkout paths
- Updated documentation (README, CLI reference, overview) to reflect URL support
Show a summary per file
| File | Description |
|---|---|
| cmd/link.go | Added parsePRURL check in findExistingPR before numeric parsing; errors immediately if URL-specified PR not found (URLs can never be branch names). Updated command help text and examples. |
| cmd/checkout.go | Added parsePRURL check in runCheckout before numeric parsing; routes extracted number to resolveNumericTarget for consistent local/remote resolution. Updated command help text and examples. |
| cmd/link_test.go | 3 new tests: URL stack creation, URL not-found error, mixed URLs and numbers. |
| cmd/checkout_test.go | 2 new tests: URL resolving against local stack (no API), URL triggering remote stack import. |
| README.md | Updated checkout and link sections to mention PR URLs with examples. |
| docs/src/content/docs/reference/cli.md | Mirror of README documentation updates for the docs site. |
| docs/src/content/docs/introduction/overview.md | Updated overview bullet to mention URL support for checkout. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 7/7 changed files
- Comments generated: 0
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.
Accept PR URLs as arguments in
linkandcheckoutCurrently,
gh stack linkandgh stack checkoutonly accept PR numbers (e.g.42) or branch names as arguments. Users who copy-paste a PR URL from the GitHub UI (e.g.https://github.com/owner/repo/pull/42) get confusing behavior — the URL is interpreted as a branch name, which either fails silently or produces an unhelpful error.A
parsePRURLhelper already existed incmd/utils.go(used byswitch,navigate, etc. for local stack resolution), but was not wired intolinkorcheckout.This change adds PR URL parsing to both commands so that
gh stack link https://github.com/o/r/pull/41 https://github.com/o/r/pull/42works the same asgh stack link 41 42, andgh stack checkout https://github.com/o/r/pull/42works the same asgh stack checkout 42.Changes
cmd/link.go: infindExistingPR, add aparsePRURLcheck before thestrconv.Atoinumeric path. If a URL is detected but the PR does not exist, error immediately (a URL can never be a valid branch name, so falling through to branch lookup would be wrong). Update command help text and examples.cmd/checkout.go: inrunCheckout, add aparsePRURLcheck before thestrconv.Atoicheck. Route the extracted PR number toresolveNumericTarget, enabling both local lookup and remote API fallback — same behavior as passing a PR number directly. Update command help text and examples.cmd/link_test.go: 3 new tests — PR URLs creating a stack, URL for non-existent PR producing an error, mixed URLs and numberscmd/checkout_test.go: 2 new tests — PR URL resolving against a local stack (no API), PR URL triggering remote stack importREADME.md,docs/src/content/docs/reference/cli.md,docs/src/content/docs/introduction/overview.md,docs/src/content/docs/faq.md: update documentation to mention PR URLs as accepted inputCloses #115
Stack created with GitHub Stacks CLI • Give Feedback 💬