Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fixed GitLab topic filters being incorrectly case-sensitive. [#1393](https://github.com/sourcebot-dev/sourcebot/pull/1393)
- 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)
- 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)
- Fixed the Review Agent failing to fetch pull request diffs for private GitHub repositories. [#1352](https://github.com/sourcebot-dev/sourcebot/pull/1352)

## [5.1.5] - 2026-07-31

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,30 @@ describe('githubPrParser', () => {
expect(result.description).toBe('');
});

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

await githubPrParser(octokit, pr);
await githubPrParser(octokit, pr);

expect(mockRequest).toHaveBeenCalledWith('https://github.com/my-org/my-repo/pull/7.diff');
});
expect(mockRequest).toHaveBeenCalledWith(
'GET /repos/{owner}/{repo}/pulls/{pull_number}',
{
owner: 'my-org',
repo: 'my-repo',
pull_number: 7,
headers: {
accept: 'application/vnd.github.diff',
},
}
);
});

test('returns empty file_diffs for an empty diff', async () => {
const octokit = makeMockOctokit('');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,23 @@ export const githubPrParser = async (octokit: Octokit, pullRequest: GitHubPullRe

let parsedDiff: parse.File[] = [];
try {
const diff = await octokit.request(pullRequest.diff_url);
parsedDiff = parse(diff.data);
} catch (error) {
logger.error("Error fetching diff: ", error);
throw error;
}
const { owner, name: repo } = pullRequest.base.repo;
const pullNumber = pullRequest.number;

const diff = await octokit.request("GET /repos/{owner}/{repo}/pulls/{pull_number}", {
owner: owner.login,
repo,
pull_number: pullNumber,
headers: {
accept: "application/vnd.github.diff",
},
});

parsedDiff = parse(diff.data as unknown as string);
} catch (error) {
logger.error("Error fetching diff: ", error);
throw error;
}

const sourcebotFileDiffs: (sourcebot_file_diff | null)[] = parsedDiff.map((file) => {
if (!file.from || !file.to) {
Expand Down Expand Up @@ -64,4 +75,4 @@ export const githubPrParser = async (octokit: Octokit, pullRequest: GitHubPullRe
number: pullRequest.number,
head_sha: pullRequest.head.sha
}
}
}
Loading