fix(web): use REST API endpoint for fetching PR diff instead of web diff_url#1302
Conversation
…iff_url
The Review Agent's githubPrParser was using pullRequest.diff_url to
fetch the PR diff, which points to a github.com web URL. GitHub App
installation tokens are only accepted on the REST API (api.github.com),
so requests to the web domain fail with 404 for private repositories.
Fix by using the REST API endpoint GET /repos/{owner}/{repo}/pulls/{pull_number}
with mediaType: { format: 'diff' }, which correctly authenticates with
the installation token and works for both public and private repos.
Fixes sourcebot-dev#1277
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
✅ Files skipped from review due to trivial changes (1)
WalkthroughThe Review Agent's PR diff parser now uses the GitHub REST API's ChangesGitHub PR Diff Fetching via REST API
Sequence Diagram(s)sequenceDiagram
participant githubPrParser
participant Octokit
participant parseDiff as parse-diff
participant Sourcebot
githubPrParser->>Octokit: GET /repos/{owner}/{repo}/pulls/{pull_number} (mediaType: diff)
Octokit-->>githubPrParser: diff text (diff.data)
githubPrParser->>parseDiff: parse(diff.data as string)
parseDiff-->>githubPrParser: parsed file/chunk structures
githubPrParser->>Sourcebot: sourcebot_pr_payload (includes head_sha, file_diffs)
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
packages/web/src/features/agents/review-agent/nodes/githubPrParser.test.ts (1)
16-51: 💤 Low valueConsider removing the unused
diff_urlfield.The
makePullRequesthelper includes adiff_urlfield (lines 24, 34, 42) that is no longer accessed by the implementation. Since the parser now uses the REST API endpoint directly, this field is dead code in the test factory.However, keeping it might be intentional to maintain the complete shape of a
GitHubPullRequestobject for test fidelity.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/web/src/features/agents/review-agent/nodes/githubPrParser.test.ts` around lines 16 - 51, The makePullRequest test helper includes an unused diff_url property on the overrides type, opts default object and returned GitHubPullRequest shape; remove diff_url from the overrides Partial type, from the opts defaults, and from the returned object in makePullRequest (function name: makePullRequest) so the helper matches the fields actually consumed by the parser (GitHubPullRequest) — or if you want to preserve full PR shape for fidelity, keep it but add a comment clarifying it’s unused.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@CHANGELOG.md`:
- Around line 10-12: Update the CHANGELOG entry that currently reads "Fixed
Review Agent failing on private GitHub repositories when fetching the PR
diff..." to reference the pull request instead of the issue: replace the
existing issue link
[`#1277`](https://github.com/sourcebot-dev/sourcebot/issues/1277) with the PR link
for PR `#1302` formatted as
[`#1302`](https://github.com/sourcebot-dev/sourcebot/pull/1302) so the line ends
with the correct PR reference.
---
Nitpick comments:
In `@packages/web/src/features/agents/review-agent/nodes/githubPrParser.test.ts`:
- Around line 16-51: The makePullRequest test helper includes an unused diff_url
property on the overrides type, opts default object and returned
GitHubPullRequest shape; remove diff_url from the overrides Partial type, from
the opts defaults, and from the returned object in makePullRequest (function
name: makePullRequest) so the helper matches the fields actually consumed by the
parser (GitHubPullRequest) — or if you want to preserve full PR shape for
fidelity, keep it but add a comment clarifying it’s unused.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 6659c80f-fa12-4a11-8805-b17185f00cd8
📒 Files selected for processing (3)
CHANGELOG.mdpackages/web/src/features/agents/review-agent/nodes/githubPrParser.test.tspackages/web/src/features/agents/review-agent/nodes/githubPrParser.ts
Description
Fixes the Review Agent failing on private GitHub repositories when fetching the PR diff. The
githubPrParserwas usingpullRequest.diff_urlfrom the GitHub API, which returns agithub.comweb URL (e.g.https://github.com/owner/repo/pull/123.diff). GitHub App installation tokens are only accepted by the REST API atapi.github.com, so requests to the web domain return 404 for private repositories.The fix replaces the web URL with the REST API endpoint
GET /repos/{owner}/{repo}/pulls/{pull_number}usingmediaType: { format: 'diff' }, which correctly authenticates with the installation token and returns the diff for both public and private repos.Related Issue(s)
Type of Change
Changes Made
githubPrParser.tsto fetch the PR diff viaoctokit.request('GET /repos/{owner}/{repo}/pulls/{pull_number}', { mediaType: { format: 'diff' } })instead ofoctokit.request(pullRequest.diff_url)githubPrParser.test.tsto verify the REST API endpoint is called with correct parameters[Unreleased] > FixedTesting
github.comtoapi.github.comChecklist
Additional Notes
The root cause was traced through Octokit's
endpoint.parse()(@octokit/endpoint/dist-src/parse.js:20): when an absolute URL is passed (like thediff_url), thebaseUrlis never prepended, so the request goes togithub.cominstead ofapi.github.comwhere the installation token is valid. The existing code inwebhook/route.ts:189already uses the correct REST API pattern (octokit.rest.pulls.get) for fetching PR data from commentSummary by CodeRabbit
Bug Fixes
New Features
Tests