fix: handle missing comment payload in Forgejo review comment events

Forgejo's pull_request_review_comment event does not include a
top-level `comment` object in the payload (it's undefined), causing
a crash: "undefined is not an object (evaluating 'context.payload.comment.body')".

- trigger.ts: On Forgejo, always trigger for pull_request_review_comment
  events since the workflow already gates on event name alone
- create-prompt/index.ts: Use optional chaining for comment fields,
  fall back to actor/empty values (data fetcher provides full data)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Vlad MocanuandClaude Opus 4.6 committed 2026-02-25 23:53:19 +02:00
1 parent b4bc36810d
commit a10b0475c0
2 files changed
+23 -3

No files matched your search

+7 -3
View File
@@ -142,9 +142,13 @@ export function prepareContext(
commentBody = context.payload.review.body ?? ""; commentBody = context.payload.review.body ?? "";
triggerUsername = context.payload.review.user.login; triggerUsername = context.payload.review.user.login;
} else if (isPullRequestReviewCommentEvent(context)) { } else if (isPullRequestReviewCommentEvent(context)) {
commentId = context.payload.comment.id.toString(); // Forgejo's pull_request_review_comment payload may not include a
commentBody = context.payload.comment.body; // top-level `comment` object. Use optional chaining and fall back
triggerUsername = context.payload.comment.user.login; // to actor/empty values — the data fetcher provides the full data.
commentId = (context.payload as any).comment?.id?.toString();
commentBody = (context.payload as any).comment?.body ?? "";
triggerUsername =
(context.payload as any).comment?.user?.login ?? context.actor;
} else if (isIssuesEvent(context)) { } else if (isIssuesEvent(context)) {
triggerUsername = context.payload.issue.user.login; triggerUsername = context.payload.issue.user.login;
} }
+16
View File
@@ -10,6 +10,7 @@ import {
isPullRequestReviewCommentEvent, isPullRequestReviewCommentEvent,
} from "../context"; } from "../context";
import type { ParsedGitHubContext } from "../context"; import type { ParsedGitHubContext } from "../context";
import { detectPlatform } from "../../platform/detector";
export function checkContainsTrigger(context: ParsedGitHubContext): boolean { export function checkContainsTrigger(context: ParsedGitHubContext): boolean {
const { const {
@@ -119,6 +120,21 @@ export function checkContainsTrigger(context: ParsedGitHubContext): boolean {
isIssueCommentEvent(context) || isIssueCommentEvent(context) ||
isPullRequestReviewCommentEvent(context) isPullRequestReviewCommentEvent(context)
) { ) {
// Forgejo's pull_request_review_comment payload does NOT include a
// top-level `comment` object (it's undefined). On Forgejo, the
// workflow `if:` already gates on event name alone, so always trigger
// here — the actual comment data is fetched via REST in the data
// fetcher, and non-matching comments won't produce useful output.
if (
isPullRequestReviewCommentEvent(context) &&
detectPlatform() === "forgejo"
) {
console.log(
"Forgejo pull_request_review_comment: triggering (payload lacks comment body)",
);
return true;
}
const commentBody = isIssueCommentEvent(context) const commentBody = isIssueCommentEvent(context)
? context.payload.comment.body ? context.payload.comment.body
: context.payload.comment.body; : context.payload.comment.body;