parse PR URLs in args#122
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>
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
| Long: `Check out a stack from a pull request number or branch name. | ||
| Use: "checkout [<pr-number> | <pr-url> | <branch>]", | ||
| Short: "Checkout a stack from a PR number, PR URL, or branch name", | ||
| Long: `Check out a stack from a pull request number, PR URL, or branch name. |
There was a problem hiding this comment.
Nit: I know this is in the previous code too, but why does Long have a back tick but the Use and Short use double quotes " since there is no string interpolation here?
There was a problem hiding this comment.
We use backticks for the Long descriptions because it's a multi-line text and raw string literals preserve the line breaks. I guess we could use backticks for all of the strings here, but I feel like using double quotes (interpreted string literal) is usually safer and a better default 🤷
| # Check out a stack by PR URL | ||
| $ gh stack checkout https://github.com/owner/repo/pull/42 |
Lukeghenco
left a comment
There was a problem hiding this comment.
I like the added utility this adds to the CLI. Looks good to 🚢.
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 💬