fix: handle missing comment payload in Forgejo pull_request_review_comment

Forgejo's pull_request_review_comment event does NOT include a top-level
`comment` object in the webhook payload. This caused crashes at:
- create-initial.ts: context.payload.comment.id (for reply-to-review)
- fetcher.ts: context.payload.comment.created_at (for trigger timestamp)

Fix: use optional chaining and fall back gracefully — reply-to-review
becomes a regular issue comment, trigger timestamp returns undefined.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Vlad MocanuandClaude Opus 4.6 committed 2026-02-26 08:39:48 +02:00
1 parent a10b0475c0
commit 9d8c96f01e
2 files changed
+16 -3

No files matched your search

+2 -1
View File
@@ -40,7 +40,8 @@ export function extractTriggerTimestamp(
} else if (isPullRequestReviewEvent(context)) { } else if (isPullRequestReviewEvent(context)) {
return context.payload.review.submitted_at || undefined; return context.payload.review.submitted_at || undefined;
} else if (isPullRequestReviewCommentEvent(context)) { } else if (isPullRequestReviewCommentEvent(context)) {
return context.payload.comment.created_at || undefined; // Forgejo's pull_request_review_comment payload may lack the `comment` object
return (context.payload as any).comment?.created_at || undefined;
} }
return undefined; return undefined;
@@ -77,14 +77,26 @@ export async function createInitialComment(
}); });
} }
} else if (isPullRequestReviewCommentEvent(context)) { } else if (isPullRequestReviewCommentEvent(context)) {
// Only use createReplyForReviewComment if it's a PR review comment AND we have a comment_id // Only use createReplyForReviewComment if we have a comment_id.
// Forgejo's pull_request_review_comment payload lacks the top-level
// `comment` object, so fall back to a regular issue comment there.
const reviewCommentId = (context.payload as any).comment?.id;
if (reviewCommentId) {
response = await octokit.rest.pulls.createReplyForReviewComment({ response = await octokit.rest.pulls.createReplyForReviewComment({
owner, owner,
repo, repo,
pull_number: context.entityNumber, pull_number: context.entityNumber,
comment_id: context.payload.comment.id, comment_id: reviewCommentId,
body: initialBody, body: initialBody,
}); });
} else {
response = await octokit.rest.issues.createComment({
owner,
repo,
issue_number: context.entityNumber,
body: initialBody,
});
}
} else { } else {
// For all other cases (issues, issue comments, or missing comment_id) // For all other cases (issues, issue comments, or missing comment_id)
response = await octokit.rest.issues.createComment({ response = await octokit.rest.issues.createComment({