feat: read comment ID from GITHUB_EVENT_PATH for eyes reaction
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { readFileSync } from "node:fs";
|
||||
import * as core from "@actions/core";
|
||||
import { agents } from "./agents/index.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).
|
||||
* 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 {
|
||||
const eventName = process.env.GITHUB_EVENT_NAME;
|
||||
const prNumberRaw = process.env.GITEA_PR_NUMBER;
|
||||
@@ -69,15 +80,21 @@ function resolveEventFromEnv(): PayloadEvent | null {
|
||||
};
|
||||
}
|
||||
|
||||
if (eventName === "issue_comment" && !Number.isNaN(prNumber)) {
|
||||
return {
|
||||
trigger: "issue_comment_created",
|
||||
issue_number: prNumber,
|
||||
is_pr: true,
|
||||
comment_id: 0,
|
||||
comment_type: "issue",
|
||||
body: null,
|
||||
};
|
||||
if (eventName === "issue_comment") {
|
||||
const event = readEventPayload();
|
||||
const issueNumber = (event.issue as Record<string, unknown> | undefined)?.number as number | undefined;
|
||||
const commentId = (event.comment as Record<string, unknown> | undefined)?.id as number | undefined;
|
||||
const resolvedPrNumber = !Number.isNaN(prNumber) ? prNumber : issueNumber;
|
||||
if (resolvedPrNumber) {
|
||||
return {
|
||||
trigger: "issue_comment_created",
|
||||
issue_number: resolvedPrNumber,
|
||||
is_pr: true,
|
||||
comment_id: commentId ?? 0,
|
||||
comment_type: "issue",
|
||||
body: null,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user