Skip to content

feat(pr-review): native PR review — diffs, comments, checks, approve & merge in-app#3174

Open
mariusandra wants to merge 9 commits into
mainfrom
posthog-code/native-pr-review
Open

feat(pr-review): native PR review — diffs, comments, checks, approve & merge in-app#3174
mariusandra wants to merge 9 commits into
mainfrom
posthog-code/native-pr-review

Conversation

@mariusandra

@mariusandra mariusandra commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

What this does

Adds a native pull request review surface to PostHog Code, so a PR can be reviewed, approved, and merged without leaving the app.

2026-07-06 14 13 30 image

Surfaces

  • Inbox PR detail (/code/inbox/pulls/$reportId): below the Responder summary, the PR's changed files, comments, CI checks, and approve/merge actions now render inline.
  • Native PR view (/code/pr?prUrl=…): clicking the #123 PR badge in the sidebar task list opens an in-app view (state badge, title, author, branches, ± stats, markdown description, then the same files/comments/checks/actions stack) instead of the browser. "Open in GitHub" remains as an escape hatch.

Files changed

  • One collapsible diff per file (reusing the existing PatchedFileDiff / @pierre/diffs machinery, respecting the user's diff settings), all collapsed by default with an Expand all / Collapse all button.
  • GitHub-style "Viewed" tracking: an expanded file gets a footer row with a Viewed checkbox; checking it folds the file and scrolls it back into view. Viewed state persists per PR (capped at 50 PRs) and is fingerprinted against the patch, so files touched by new commits drop back to unviewed. Header shows N / M viewed.

Comments

  • Collapsed-by-default section merging PR conversation comments and inline review comments chronologically — avatar, author, relative time, file path + Resolved badge for review comments, markdown body, per-comment open-in-GitHub link.

Checks

  • CI status list via gh pr checks --json, sorted failed → cancelled → running → succeeded → skipped with colored status icons; rows open the check run in GitHub.
  • The header counts are filter checkboxes (failed / cancelled / running / successful / skipped); only attention-worthy buckets are shown by default. Polls every 15s while the view is mounted and visible.

Approve & merge

  • Approve (gh pr review --approve) and a merge button with method dropdown (merge / squash / rebase, via gh pr merge).
  • The merge gate mirrors github.com: red checks or merge conflicts disable the buttons with a red explanation, updating live off the checks poll. Drafts show a note plus a Ready for review button. Merged/closed PRs show a status banner.

Backend

New GitService methods on the existing gh CLI layer, each exposed through workspace-server and host-router tRPC with mirrored Zod schemas: getPrInfoByUrl, getPrChecks, getPrComments, approvePr, mergePr.

Testing

  • pnpm typecheck — all 22 packages pass
  • biome check on touched packages — clean
  • Unit tests for the viewed-files store (fingerprint invalidation, eviction cap); affected UI suites pass (77 tests)

🤖 Generated with Claude Code

Add a native pull request review surface to PostHog Code:

- Inbox PR detail now lists all changed files under the summary as
  collapsible diffs with GitHub-style "Viewed" tracking, plus approve
  and merge buttons.
- The sidebar PR badge opens a new native /code/pr view (description,
  files changed, approve/merge) instead of the browser.
- Viewed state persists per PR and is fingerprinted against the patch,
  so files touched by new commits drop back to unviewed.
- New GitService methods getPrInfoByUrl, approvePr and mergePr (gh CLI),
  exposed through workspace-server and host-router tRPC.

Generated-By: PostHog Code
Task-Id: 62132ab5-28e5-428b-922e-0773b75024a5
Show the PR's CI status between the files-changed list and the
approve/merge buttons, on both the inbox PR detail and the native
/code/pr view:

- Checks sorted failed → running → succeeded (cancelled with failed,
  skipped last), with colored status icons; clicking a check opens it
  in GitHub.
- Collapsible section whose header always shows a per-bucket summary;
  starts collapsed when all checks are green, expanded otherwise.
- Polls every 15s while the view is mounted and the window is visible.
- New GitService.getPrChecks backed by `gh pr checks --json`, exposed
  through workspace-server and host-router tRPC.

Generated-By: PostHog Code
Task-Id: 62132ab5-28e5-428b-922e-0773b75024a5
Show GitHub comments above the checks section on both the inbox PR
detail and the native /code/pr view:

- Merges PR conversation comments with inline review comments into one
  chronological list (avatar, author, relative time, file path chip and
  Resolved badge for review comments, markdown-rendered body, and an
  open-in-GitHub link per comment).
- Collapsed by default; the header always shows the comment count.
- New GitService.getPrComments (issue comments via gh api); inline
  review comments reuse the existing getPrReviewComments endpoint.
- Extracts the shared PrSectionHeader used by both the comments and
  checks sections.

Generated-By: PostHog Code
Task-Id: 62132ab5-28e5-428b-922e-0773b75024a5
- Draft PRs get a "Ready for review" button next to the can't-merge
  note, backed by the existing updatePrByUrl "ready" action.
- The checks header counts are now filter checkboxes (failed /
  cancelled / running / successful / skipped); only failed and running
  are shown by default, replacing the whole-section collapse.
- Files changed start fully collapsed with an Expand all / Collapse all
  button in the section header.
- The "Viewed" checkbox moves from the file header row to a footer row
  under the expanded diff; marking viewed still folds the file. The
  now-unused headerTrailing plumbing is reverted from the shared diff
  components.

Generated-By: PostHog Code
Task-Id: 62132ab5-28e5-428b-922e-0773b75024a5
- Marking a file viewed collapses a diff that can be thousands of
  pixels tall, leaving the viewport staring at blank space below.
  Scroll the folded file container back into view after the collapse
  commits (scrollIntoView block:nearest on the next frame).
- The comments section silently hid itself when the conversation-
  comments fetch failed but review threads were empty, which read as
  "no comments". Any source failure with nothing to show now renders
  the couldn't-load message instead.

Generated-By: PostHog Code
Task-Id: 62132ab5-28e5-428b-922e-0773b75024a5
Gate the merge button and its method dropdown like github.com: when any
CI check is failing, or the PR has merge conflicts (mergeable === false),
both are disabled and a red note explains why ("N checks are failing —
merging is blocked until they pass." / conflicts message). The gate
reuses the checks section's polling query, so it locks the moment a
check goes red and unlocks when a rerun goes green.

Generated-By: PostHog Code
Task-Id: 62132ab5-28e5-428b-922e-0773b75024a5
@trunk-io

trunk-io Bot commented Jul 6, 2026

Copy link
Copy Markdown

Merging to main in this repository is managed by Trunk.

  • To merge this pull request, check the box to the left or comment /trunk merge below.

After your PR is submitted to the merge queue, this comment will be automatically updated with its status. If the PR fails, failure details will also be posted here

@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown

React Doctor found 5 issues in 4 files · 5 warnings.

5 warnings

src/features/inbox/components/PullRequestDetail.tsx

src/features/pr-review/PrChecksSection.tsx

src/features/pr-review/PrCommentsSection.tsx

src/features/pr-review/PrFilesChangedSection.tsx

Reviewed by React Doctor for commit 4b0e2cf.

@greptile-apps

greptile-apps Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Comments Outside Diff (1)

  1. packages/core/src/git/router-schemas.ts, line 437-534 (link)

    P2 Schema definitions duplicated across two packages

    The five schema groups added here (getPrInfoByUrlOutput, prCheckSchema, prConversationCommentSchema, approvePrOutput, mergePrOutput) are byte-for-byte copies of the same schemas in packages/workspace-server/src/services/git/schemas.ts. Each "Mirrors X" comment acknowledges this. Two independent copies will inevitably drift — a field added to one won't automatically be added to the other, and the Zod mismatch only surfaces at runtime. If the package boundary prevents direct import, an intermediate shared package (or re-exporting from core) would keep the definition in one place.

    Context Used: Do not attempt to comment on incorrect alphabetica... (source)

    Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Reviews (1): Last reviewed commit: "feat(pr-review): block merge buttons on ..." | Re-trigger Greptile

Comment thread packages/ui/src/features/pr-review/PrReviewActions.tsx
Comment thread packages/workspace-server/src/services/git/service.ts
Review feedback (greptile / React Doctor):
- Block the merge buttons when CI status is unknown (checks fetch
  failed or still loading), not just when checks are red — a transient
  gh error no longer silently unlocks the merge.
- Zod-parse the getPrInfoByUrl response instead of casting, and
  validate each comment line against the schema.
- Lazy-init the file-container ref map.

Comment loading fixes:
- execGh now defaults maxBuffer to 32 MiB; Node's 1 MiB execFile
  default killed paginated gh api calls (comments, PR files) on busy
  PRs with "maxBuffer length exceeded".
- getPrComments slims each comment to the schema fields inside gh's
  --jq (NDJSON per line; --slurp can't combine with --jq), shrinking
  the payload ~10x, and now also merges in PR review summaries —
  GitHub's conversation tab is both feeds.
- Failures now throw with the real gh error instead of returning null,
  and the comments section surfaces that message under the
  couldn't-load line for diagnosability.

Viewed UX:
- Collapsed files get a "Viewed" checkbox in the header row (via the
  headerTrailing slot; NestedButton since the header is a <button>).
- Expanded files get a "Collapse" link left of the footer checkbox;
  both it and mark-as-viewed share the scroll-back-into-view handling.

Generated-By: PostHog Code
Task-Id: 62132ab5-28e5-428b-922e-0773b75024a5
… gate

- Closed (not merged) PRs get a "Reopen" button in the status banner,
  via the existing updatePrByUrl "reopen" action.
- The five native-PR-review schema groups (PR info, checks, comments,
  approve, merge) now live once in @posthog/shared's git-domain and are
  re-exported by core's router-schemas and workspace-server's git
  schemas — addresses greptile's duplication finding; ~180 mirrored
  lines removed with all import paths unchanged.
- getPrInfoByUrl carries GitHub's mergeable_state as mergeStateStatus.
  "blocked" (branch protection — e.g. a required approving review the
  PR author can't self-provide) and "behind" now disable the merge
  buttons with an explanation, matching github.com. Repos without
  protection rules report clean/unstable and are unaffected.

Generated-By: PostHog Code
Task-Id: 62132ab5-28e5-428b-922e-0773b75024a5
The activity log's "Commit pushed" entries carry a View/Hide diff
toggle. On the inbox PR detail the main column already lists every
changed file, so the per-commit diff is redundant there — thread a
hideCommitDiffs flag from PullRequestDetail through
ReportActivitySection and ArtefactLogList to ArtefactCommit, set under
the same condition that renders the files-changed section. Other
report detail surfaces keep the toggle.

Generated-By: PostHog Code
Task-Id: 62132ab5-28e5-428b-922e-0773b75024a5
@mariusandra mariusandra added the Stamphog This will request an autostamp by stamphog on small changes label Jul 6, 2026

@stamphog stamphog 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.

This PR exceeds the automated review size limits and introduces substantial new functionality (native PR review with diffs, comments, checks, approve & merge). The only reviews are from a bot on an older commit. Request a human team member review before re-requesting auto-approval.

@stamphog stamphog Bot removed the Stamphog This will request an autostamp by stamphog on small changes label Jul 6, 2026
@charlesvien charlesvien requested a review from adboio July 6, 2026 21:58
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