Skip to content

feat(PRO-545): review a GitHub PR by URL or number#67

Merged
dastratakos merged 4 commits into
mainfrom
dean/pro-545-open-a-review-directly-from-a-pr-url-or-number
Jun 7, 2026
Merged

feat(PRO-545): review a GitHub PR by URL or number#67
dastratakos merged 4 commits into
mainfrom
dean/pro-545-open-a-review-directly-from-a-pr-url-or-number

Conversation

@dastratakos

@dastratakos dastratakos commented Jun 7, 2026

Copy link
Copy Markdown
Contributor

Summary

Lets you point the CLI at a GitHub PR — --pr <number-or-url> on both stagereview prep and show — and review it instead of only your local branch diff. The base/head come from the PR itself (its commits are fetched into the local clone, leaving your working tree untouched) rather than the current branch's heuristic base detection, so you can review a teammate's PR without checking it out. The reviewed PR number is persisted on chapter_run so the PR header, CI checks, reviews, and merge controls resolve the targeted PR rather than whatever branch happens to be checked out.

Changes

  • Add --pr to prep/show, resolving a PR ref (number, #123, or github.com URL) to local base/head SHAs via gh + git fetch pull/N/head, validating same-repo and surfacing actionable errors.
  • Add scope.ts (resolveDiffScope) to unify local-ref and PR scope resolution, and consolidate the per-command diff options into a single object.
  • Add a nullable prNumber column to chapter_run (migration 0005) and thread it through ingestion and the /pull-request route so getPullRequest loads the targeted PR.
  • Extract a shared ghErrorMessage helper; document --pr in the README and the stage-chapters skill.

Testing

  • pnpm typecheck && pnpm lint && pnpm test — all green (307 tests), including new unit tests for the PR-ref parser and a route test proving the prNumber column round-trips and is forwarded to gh.
  • Manual end-to-end smoke test: stagereview prep --pr 62 resolved and fetched PR feat(PRO-544): add write capability to the PR header #62, and the validation/error paths (--pr + other flags, invalid ref, nonexistent PR) all surfaced the expected messages.

Open in Stage

Summary by cubic

Review a GitHub PR by number or URL with --pr on stagereview prep and show, with parsing locked to github.com. Implements Linear PRO-545.

  • New Features

    • --pr <number-or-url> on prep/show; accepts a number, #123, or a GitHub PR URL; validates same-repo, uses gh to resolve base/head, and fetches refs/pull/<N>/head.
    • Persist prNumber on chapter_run and forward it to /pull-request; getPullRequest targets gh pr view <N> so the UI matches the selected PR. Also honored when showing a complete chapters file by recording only the PR number (no fetch), ensuring the PR header resolves correctly.
    • Hardened PR URL parsing and shared origin validation via parsePullRequestRef, preventing look‑alike hosts and keeping both PR-resolution paths consistent.
  • Migration

    • Run CLI DB migrations (adds prNumber to chapter_run).
    • Requires gh installed and authenticated with a github.com origin; --pr cannot be combined with positional refs, --base, --compare, or --ref.

Written for commit d71f48c. Summary will update on new commits.

Review in cubic

@stage-review

stage-review Bot commented Jun 7, 2026

Copy link
Copy Markdown

Ready to review this PR? Stage has broken it down into 6 individual chapters for you:

Title
1 Add prNumber column to chapter_run table
2 Implement GitHub PR reference parsing and fetching
3 Unify diff scope resolution logic
4 Integrate PR resolution into prep and show
5 Persist and forward prNumber through API
6 Update documentation and skills for PR support
Open in Stage

Chapters generated by Stage for commit d71f48c on Jun 7, 2026 7:12pm UTC.

Add `--pr <number-or-url>` to `prep` and `show`. The base/head come from
the PR itself (fetched into the local clone) rather than the current
branch's heuristic base detection, so teammates' PRs can be reviewed
without checking them out.

The reviewed PR number is persisted on `chapter_run` so the PR header,
checks, reviews, and merge controls resolve the targeted PR instead of
the checked-out branch's PR.
@dastratakos dastratakos force-pushed the dean/pro-545-open-a-review-directly-from-a-pr-url-or-number branch from 11804d3 to a3d4ebe Compare June 7, 2026 18:21

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit a3d4ebe. Configure here.

Comment thread packages/cli/src/github/pull-request-ref.ts
@dastratakos dastratakos marked this pull request as ready for review June 7, 2026 18:44
PR_URL_RE matched github.com as a bare substring, so a look-alike host
such as https://notgithub.com/owner/repo/pull/123 was accepted when the
owner/repo matched the local remote. Anchor the host to a boundary
(start, after @, or after //), mirroring parseGitHubRepo.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

cubic analysis

1 issue found across 21 files

Linked issue analysis

Linked issue: PRO-545: Open a review directly from a PR URL or number

Status Acceptance criteria Notes
Add a --pr option to prep and show that accepts a bare number, #N, or a github.com PR URL CLI wiring, docs, and tests show the option is present and parsed. The option is added in index.ts, README and skill docs updated, and parse tests exercise URL/number parsing.
Parse and validate PR references (number or github.com URL) and reject look-alike hosts or cross-repo URLs PR-ref parser enforces github.com host boundaries and verifies owner/repo matches the current repo, throwing actionable errors for invalid refs or different repositories.
Resolve PR to local base/head SHAs by calling gh and fetching the PR head (refs/pull/N/head), surfacing actionable gh/git error messages Implementation loads PR metadata via gh, fetches the PR head and base branch into the local clone, and surfaces errors using a ghErrorMessage helper for actionable diagnostics.
Use the PR's base/head (not local branch heuristics) for computing the diff while leaving the working tree untouched The new resolveDiffScope path calls resolvePullRequestRefs and then uses resolved SHAs to compute the committed comparison; runPrep/show are updated to use this unified scope so the diff is based on the PR's endpoints.
Persist the targeted PR number on chapter_run and thread it through ingestion and the /pull-request route so UI loads the selected PR instead of the checked-out branch DB migration and schema add prNumber to chapter_run, insert flows record it, and the pull-request route forwards prNumber to getPullRequest; a test verifies the prNumber is forwarded to gh.
Disallow combining --pr with positional refs, --base, --compare, or --ref, and document the feature CLI input is validated so --pr cannot be combined with other ref selectors; docs show usage and constraints.

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread packages/cli/src/show.ts Outdated
A full chapters file carries its own scope, so show returned prNumber:
null and silently ignored --pr — the PR header would then resolve the
checked-out branch's PR instead of the targeted one. Record the PR
number on that path too. Only the number is resolved (no fetch), since
the diff scope still comes from the file, keeping a self-contained file
viewable offline.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

1 issue found across 2 files (changes from recent commits).

Tip: Review your code locally with the cubic CLI to iterate faster.

Re-trigger cubic

Comment thread packages/cli/src/scope.ts Outdated
Both PR-resolution paths validated the github.com origin independently.
Extract parsePullRequestRef (origin check + number parse) and route the
fetch-and-diff path and the number-only path through it, so the check
can't drift.
@dastratakos dastratakos merged commit ca4d94a into main Jun 7, 2026
6 checks passed
@dastratakos dastratakos deleted the dean/pro-545-open-a-review-directly-from-a-pr-url-or-number branch June 7, 2026 22:04
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.

1 participant