feat: read comment ID from GITHUB_EVENT_PATH for eyes reaction

This commit is contained in:
2026-05-31 19:08:59 -05:00
parent 6c03caa8ea
commit 628a3692ff
+26 -9
View File
@@ -1,3 +1,4 @@
import { readFileSync } from "node:fs";
import * as core from "@actions/core"; import * as core from "@actions/core";
import { agents } from "./agents/index.ts"; import { agents } from "./agents/index.ts";
import type { PayloadEvent } from "./external.ts"; import type { PayloadEvent } from "./external.ts";
@@ -53,6 +54,16 @@ function parseRepoContext(): { owner: string; name: string } {
* from Gitea Actions environment variables (GITHUB_EVENT_NAME, GITEA_PR_NUMBER). * from Gitea Actions environment variables (GITHUB_EVENT_NAME, GITEA_PR_NUMBER).
* Returns null when the env vars aren't set (e.g. local dev run). * Returns null when the env vars aren't set (e.g. local dev run).
*/ */
function readEventPayload(): Record<string, unknown> {
try {
const eventPath = process.env.GITHUB_EVENT_PATH;
if (!eventPath) return {};
return JSON.parse(readFileSync(eventPath, "utf-8"));
} catch {
return {};
}
}
function resolveEventFromEnv(): PayloadEvent | null { function resolveEventFromEnv(): PayloadEvent | null {
const eventName = process.env.GITHUB_EVENT_NAME; const eventName = process.env.GITHUB_EVENT_NAME;
const prNumberRaw = process.env.GITEA_PR_NUMBER; const prNumberRaw = process.env.GITEA_PR_NUMBER;
@@ -69,15 +80,21 @@ function resolveEventFromEnv(): PayloadEvent | null {
}; };
} }
if (eventName === "issue_comment" && !Number.isNaN(prNumber)) { if (eventName === "issue_comment") {
return { const event = readEventPayload();
trigger: "issue_comment_created", const issueNumber = (event.issue as Record<string, unknown> | undefined)?.number as number | undefined;
issue_number: prNumber, const commentId = (event.comment as Record<string, unknown> | undefined)?.id as number | undefined;
is_pr: true, const resolvedPrNumber = !Number.isNaN(prNumber) ? prNumber : issueNumber;
comment_id: 0, if (resolvedPrNumber) {
comment_type: "issue", return {
body: null, trigger: "issue_comment_created",
}; issue_number: resolvedPrNumber,
is_pr: true,
comment_id: commentId ?? 0,
comment_type: "issue",
body: null,
};
}
} }
return null; return null;