From a10b0475c067714c701f013ba2d272e00e83a158 Mon Sep 17 00:00:00 2001 From: Vlad Mocanu Date: Wed, 25 Feb 2026 23:53:11 +0200 Subject: [PATCH] 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 --- src/create-prompt/index.ts | 10 +++++++--- src/github/validation/trigger.ts | 16 ++++++++++++++++ 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/create-prompt/index.ts b/src/create-prompt/index.ts index d9f99cd..a257833 100644 --- a/src/create-prompt/index.ts +++ b/src/create-prompt/index.ts @@ -142,9 +142,13 @@ export function prepareContext( commentBody = context.payload.review.body ?? ""; triggerUsername = context.payload.review.user.login; } else if (isPullRequestReviewCommentEvent(context)) { - commentId = context.payload.comment.id.toString(); - commentBody = context.payload.comment.body; - triggerUsername = context.payload.comment.user.login; + // Forgejo's pull_request_review_comment payload may not include a + // top-level `comment` object. Use optional chaining and fall back + // 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)) { triggerUsername = context.payload.issue.user.login; } diff --git a/src/github/validation/trigger.ts b/src/github/validation/trigger.ts index 74b385d..c16cdf1 100644 --- a/src/github/validation/trigger.ts +++ b/src/github/validation/trigger.ts @@ -10,6 +10,7 @@ import { isPullRequestReviewCommentEvent, } from "../context"; import type { ParsedGitHubContext } from "../context"; +import { detectPlatform } from "../../platform/detector"; export function checkContainsTrigger(context: ParsedGitHubContext): boolean { const { @@ -119,6 +120,21 @@ export function checkContainsTrigger(context: ParsedGitHubContext): boolean { isIssueCommentEvent(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) ? context.payload.comment.body : context.payload.comment.body;