Skip to content

fix(review-agent): fetch private GitHub PR diffs via API#1352

Open
BashOpsDev wants to merge 5 commits into
sourcebot-dev:mainfrom
BashOpsDev:fix/private-pr-diff-fetch
Open

fix(review-agent): fetch private GitHub PR diffs via API#1352
BashOpsDev wants to merge 5 commits into
sourcebot-dev:mainfrom
BashOpsDev:fix/private-pr-diff-fetch

Conversation

@BashOpsDev

@BashOpsDev BashOpsDev commented Jun 18, 2026

Copy link
Copy Markdown

Summary

Fixes #1277.

The Review Agent currently fetches pull request diffs using the diff_url returned by GitHub. For private repositories, this URL can return 404 Not Found even when the GitHub App token has permission to access the pull request through the GitHub API.

This change updates githubPrParser to fetch diffs through the GitHub Pull Requests API using the application/vnd.github.diff accept header. This allows authenticated access to PR diffs in private repositories.

Changes

  • Replace direct requests to pullRequest.diff_url
  • Fetch PR diffs using GET /repos/{owner}/{repo}/pulls/{pull_number}
  • Request diff content via application/vnd.github.diff
  • Update tests to verify API-based diff fetching

Testing

cd packages/web
yarn vitest githubPrParser

Result:

  • Test Files: 1 passed
  • Tests: 9 passed

Summary by CodeRabbit

  • Bug Fixes
    • Updated pull request diff retrieval to use the official GitHub Pulls API endpoint with the correct diff Accept header, instead of relying on the pull request’s direct diff URL.
    • Updated the related test to verify the new API request behavior and expected parameters.

@coderabbitai

coderabbitai Bot commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 4a3f9afa-74f4-405d-8e20-ceab02c82382

📥 Commits

Reviewing files that changed from the base of the PR and between a43e11b and fb3a212.

📒 Files selected for processing (1)
  • packages/web/src/features/agents/review-agent/nodes/githubPrParser.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/web/src/features/agents/review-agent/nodes/githubPrParser.ts

Walkthrough

githubPrParser now fetches pull request diffs through the GitHub Pulls API with the diff media type, instead of reading pullRequest.diff_url. The test was updated to match the new request shape.

Changes

Authenticated PR diff fetching via Octokit Pulls API

Layer / File(s) Summary
Diff fetch via Octokit Pulls API
packages/web/src/features/agents/review-agent/nodes/githubPrParser.ts, packages/web/src/features/agents/review-agent/nodes/githubPrParser.test.ts
githubPrParser derives owner, repo, and pull_number from the pull request, requests GET /repos/{owner}/{repo}/pulls/{pull_number} with accept: application/vnd.github.diff, and parses the returned diff string. The test asserts the updated Octokit request arguments and header.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main fix: fetching private GitHub PR diffs through the API.
Linked Issues check ✅ Passed The parser now uses the GitHub Pulls API with a diff accept header, which addresses private-repo diff fetching in #1277.
Out of Scope Changes check ✅ Passed The changes stay focused on the diff-fetching fix and test updates, with no unrelated functionality added.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1

🤖 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 `@packages/web/src/features/agents/review-agent/nodes/githubPrParser.ts`:
- Around line 15-20: The local variable `pull_number` violates
TypeScript/JavaScript naming conventions which require camelCase for
identifiers. Rename the local variable from `pull_number` to `pullNumber` on the
line where it is assigned from `pullRequest.number`. Then in the octokit.request
call, update the parameter mapping to use `pull_number: pullNumber` to keep the
API field name in snake_case while the local variable follows camelCase
conventions.
🪄 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: 963e0c7a-35ed-491d-b985-0d8e52b18c72

📥 Commits

Reviewing files that changed from the base of the PR and between 26435a4 and 0f2efb5.

📒 Files selected for processing (2)
  • packages/web/src/features/agents/review-agent/nodes/githubPrParser.test.ts
  • packages/web/src/features/agents/review-agent/nodes/githubPrParser.ts

Comment thread packages/web/src/features/agents/review-agent/nodes/githubPrParser.ts Outdated
brendan-kellam
brendan-kellam previously approved these changes Jun 25, 2026
@BashOpsDev

Copy link
Copy Markdown
Author

Thanks for the approval @brendan-kellam.

I can take care of the remaining failing checks. I see lint and tests are passing, and the remaining failures are the PR Gate build and Changelog Reminder. I’ll inspect the logs and add a changelog entry if required.

@BashOpsDev

Copy link
Copy Markdown
Author

Thanks again @brendan-kellam.

I’ve updated the branch with latest main and fixed the PR Gate build issue. The build was failing because TypeScript inferred the Octokit diff response as the default pull request JSON shape, so I updated the diff parsing cast accordingly.

I verified locally:

yarn build

Result: completed successfully.

The branch is ready for re-review when you have a chance.

@brendan-kellam

Copy link
Copy Markdown
Contributor

@claude add a changelog entry

@claude

claude Bot commented Jun 26, 2026

Copy link
Copy Markdown

Claude finished @brendan-kellam's task in 27s —— View job


Adding changelog entry

  • Read CHANGELOG.md
  • Add entry under [Unreleased] → Fixed
  • Commit and push

Added the following entry under [Unreleased] → Fixed and pushed it to fix/private-pr-diff-fetch:

Fixed the Review Agent failing to fetch pull request diffs for private GitHub repositories by fetching diffs through the GitHub Pulls API with the diff accept header instead of the diff_url. [#1352]
· fix/private-pr-diff-fetch

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.

[bug] Review Agent fails on private GitHub repositories when fetching PR diff

2 participants