Skip to content

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

Merged
brendan-kellam merged 8 commits into
sourcebot-dev:mainfrom
BashOpsDev:fix/private-pr-diff-fetch
Aug 5, 2026
Merged

fix(review-agent): fetch private GitHub PR diffs via API#1352
brendan-kellam merged 8 commits into
sourcebot-dev:mainfrom
BashOpsDev:fix/private-pr-diff-fetch

Conversation

@BashOpsDev

@BashOpsDev BashOpsDev commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

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
    • Improved pull request diff retrieval by using the GitHub Pulls API with the appropriate diff format.
    • Added coverage to verify correct repository and pull request details are used when fetching diffs.

Note

Low Risk
Small, localized change to diff fetch in the review agent; same parsing path and no auth or data-model changes beyond using the existing Octokit token for the pulls API.

Overview
Fixes the Review Agent failing to load PR diffs on private GitHub repos by changing how githubPrParser retrieves diff text.

Instead of calling octokit.request on GitHub’s public diff_url, it now uses GET /repos/{owner}/{repo}/pulls/{pull_number} with the application/vnd.github.diff accept header so the authenticated Octokit client can read the diff. Parsing and payload mapping are unchanged; tests assert the new API call shape.

Reviewed by Cursor Bugbot for commit 4ae2913. Bugbot is set up for automated code reviews on this repo. Configure here.

@coderabbitai

coderabbitai Bot commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

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 verifies the new request parameters and header.

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
Linked Issues check ✅ Passed The PR fetches diffs through the authenticated GitHub Pulls API and updates tests, satisfying issue #1277.
Out of Scope Changes check ✅ Passed The changes are limited to GitHub PR diff retrieval and its tests, with no unrelated code changes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: fetching private GitHub pull request diffs through the API.
✨ 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
Contributor 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
Contributor 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
brendan-kellam previously approved these changes Jun 26, 2026
@brendan-kellam

Copy link
Copy Markdown
Contributor

@claude add a changelog entry

@claude

claude Bot commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

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

@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@brendan-kellam
brendan-kellam merged commit 42ba695 into sourcebot-dev:main Aug 5, 2026
9 checks passed
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