Skip to content

Commit 42ba695

Browse files
fix(review-agent): fetch private GitHub PR diffs via API (#1352)
* fix(review-agent): fetch private GitHub PR diffs via API * style(review-agent): use camelCase local variable * fix(review-agent): satisfy diff response typing * fix changelog --------- Co-authored-by: Brendan Kellam <brendan@sourcebot.dev>
1 parent f88c56a commit 42ba695

3 files changed

Lines changed: 41 additions & 14 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1313
- Fixed GitLab topic filters being incorrectly case-sensitive. [#1393](https://github.com/sourcebot-dev/sourcebot/pull/1393)
1414
- Fixed a crash when searching with `context:` referencing a search context that does not exist; it now returns a graceful error. [#1362](https://github.com/sourcebot-dev/sourcebot/pull/1362)
1515
- Fixed search queries failing to parse when negating a bare term that contains a colon (e.g. `-foo:bar`, `-http://example.com`). [#1301](https://github.com/sourcebot-dev/sourcebot/pull/1301)
16+
- Fixed the Review Agent failing to fetch pull request diffs for private GitHub repositories. [#1352](https://github.com/sourcebot-dev/sourcebot/pull/1352)
1617

1718
## [5.1.5] - 2026-07-31
1819

packages/web/src/features/agents/review-agent/nodes/githubPrParser.test.ts

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,30 @@ describe('githubPrParser', () => {
7979
expect(result.description).toBe('');
8080
});
8181

82-
test('fetches diff using the pull request diff_url', async () => {
83-
const mockRequest = vi.fn().mockResolvedValue({ data: '' });
84-
const octokit = { request: mockRequest } as unknown as Octokit;
85-
const pr = makePullRequest({ diff_url: 'https://github.com/my-org/my-repo/pull/7.diff' });
82+
test('fetches diff using the GitHub pulls API with diff accept header', async () => {
83+
const mockRequest = vi.fn().mockResolvedValue({ data: '' });
84+
const octokit = { request: mockRequest } as unknown as Octokit;
85+
const pr = makePullRequest({
86+
owner: 'my-org',
87+
repo: 'my-repo',
88+
number: 7,
89+
diff_url: 'https://github.com/my-org/my-repo/pull/7.diff',
90+
});
8691

87-
await githubPrParser(octokit, pr);
92+
await githubPrParser(octokit, pr);
8893

89-
expect(mockRequest).toHaveBeenCalledWith('https://github.com/my-org/my-repo/pull/7.diff');
90-
});
94+
expect(mockRequest).toHaveBeenCalledWith(
95+
'GET /repos/{owner}/{repo}/pulls/{pull_number}',
96+
{
97+
owner: 'my-org',
98+
repo: 'my-repo',
99+
pull_number: 7,
100+
headers: {
101+
accept: 'application/vnd.github.diff',
102+
},
103+
}
104+
);
105+
});
91106

92107
test('returns empty file_diffs for an empty diff', async () => {
93108
const octokit = makeMockOctokit('');

packages/web/src/features/agents/review-agent/nodes/githubPrParser.ts

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,23 @@ export const githubPrParser = async (octokit: Octokit, pullRequest: GitHubPullRe
1111

1212
let parsedDiff: parse.File[] = [];
1313
try {
14-
const diff = await octokit.request(pullRequest.diff_url);
15-
parsedDiff = parse(diff.data);
16-
} catch (error) {
17-
logger.error("Error fetching diff: ", error);
18-
throw error;
19-
}
14+
const { owner, name: repo } = pullRequest.base.repo;
15+
const pullNumber = pullRequest.number;
16+
17+
const diff = await octokit.request("GET /repos/{owner}/{repo}/pulls/{pull_number}", {
18+
owner: owner.login,
19+
repo,
20+
pull_number: pullNumber,
21+
headers: {
22+
accept: "application/vnd.github.diff",
23+
},
24+
});
25+
26+
parsedDiff = parse(diff.data as unknown as string);
27+
} catch (error) {
28+
logger.error("Error fetching diff: ", error);
29+
throw error;
30+
}
2031

2132
const sourcebotFileDiffs: (sourcebot_file_diff | null)[] = parsedDiff.map((file) => {
2233
if (!file.from || !file.to) {
@@ -64,4 +75,4 @@ export const githubPrParser = async (octokit: Octokit, pullRequest: GitHubPullRe
6475
number: pullRequest.number,
6576
head_sha: pullRequest.head.sha
6677
}
67-
}
78+
}

0 commit comments

Comments
 (0)