fix: use per-review comment fetching for Forgejo compatibility

Forgejo doesn't have the flat GET /pulls/{number}/comments endpoint
(returns 404). Replace pulls.listReviewComments() with a 2-phase
approach: fetch reviews first, then pulls.listCommentsForReview()
per-review in parallel. Updates tests to mock the new per-review API.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Vlad MocanuandClaude Opus 4.6 committed 2026-02-25 20:52:25 +02:00
1 parent efe30422e7
commit b4a6c34853
2 files changed
+48 -25

No files matched your search

+25 -11
View File
@@ -210,14 +210,16 @@ export async function fetchForgejoData({
let rawReviews: GitHubReview[] = [];
if (isPR) {
// Fetch PR details, files, commits, comments, reviews, and inline comments in parallel
// Phase 1: Fetch PR details, files, commits, comments, and reviews in parallel.
// Note: Forgejo doesn't have a flat /pulls/{number}/comments endpoint for
// review comments (returns 404). Instead, fetch review comments per-review
// in phase 2 after we have the review IDs.
const [
prResponse,
filesResponse,
commitsResponse,
commentsResponse,
reviewsResponse,
reviewCommentsResponse,
] = await Promise.all([
octokits.rest.pulls.get({ owner, repo, pull_number: number }),
octokits.rest.pulls.listFiles({
@@ -244,23 +246,35 @@ export async function fetchForgejoData({
pull_number: number,
per_page: 100,
}),
octokits.rest.pulls.listReviewComments({
owner,
repo,
pull_number: number,
per_page: 100,
}),
]);
const pr = prResponse.data;
const files = filesResponse.data;
const commits = commitsResponse.data;
// Phase 2: Fetch inline comments for each review in parallel.
// Forgejo uses GET /repos/{owner}/{repo}/pulls/{index}/reviews/{id}/comments
const reviewCommentArrays = await Promise.all(
reviewsResponse.data.map(async (review) => {
try {
const { data } = await octokits.rest.pulls.listCommentsForReview({
owner,
repo,
pull_number: number,
review_id: review.id,
});
return data;
} catch {
// Some reviews (e.g. pending) may not have accessible comments
return [];
}
}),
);
const allReviewCommentData = reviewCommentArrays.flat();
// Map REST responses to internal types
rawComments = mapRestComments(commentsResponse.data);
const mappedInlineComments = mapRestReviewComments(
reviewCommentsResponse.data,
);
const mappedInlineComments = mapRestReviewComments(allReviewCommentData);
rawReviews = mapRestReviews(reviewsResponse.data, mappedInlineComments);
// Map REST file objects to GitHubFile type