Skip to content

parse PR URLs in args#122

Open
skarim wants to merge 2 commits into
skarim/disable-automerge-on-adoptfrom
skarim/pr-url-args
Open

parse PR URLs in args#122
skarim wants to merge 2 commits into
skarim/disable-automerge-on-adoptfrom
skarim/pr-url-args

Conversation

@skarim

@skarim skarim commented Jun 12, 2026

Copy link
Copy Markdown
Collaborator

Accept PR URLs as arguments in link and checkout

Currently, gh stack link and gh stack checkout only 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 parsePRURL helper already existed in cmd/utils.go (used by switch, navigate, etc. for local stack resolution), but was not wired into link or checkout.

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/42 works the same as gh stack link 41 42, and gh stack checkout https://github.com/o/r/pull/42 works the same as gh stack checkout 42.

Changes

  • cmd/link.go: in findExistingPR, add a parsePRURL check before the strconv.Atoi numeric 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: in runCheckout, add a parsePRURL check before the strconv.Atoi check. Route the extracted PR number to resolveNumericTarget, 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 numbers
  • cmd/checkout_test.go: 2 new tests — PR URL resolving against a local stack (no API), PR URL triggering remote stack import
  • README.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 input

Closes #115


Stack created with GitHub Stacks CLIGive Feedback 💬

skarim and others added 2 commits June 12, 2026 02:48
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>
@skarim skarim marked this pull request as ready for review June 12, 2026 07:02
Copilot AI review requested due to automatic review settings June 12, 2026 07:02

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 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) and runCheckout (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

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.

Enhancement: Allow gh stack link to parse PR URLs, not just PR numbers

2 participants