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 * 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,16 +80,22 @@ function resolveEventFromEnv(): PayloadEvent | null {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (eventName === "issue_comment" && !Number.isNaN(prNumber)) {
|
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 {
|
return {
|
||||||
trigger: "issue_comment_created",
|
trigger: "issue_comment_created",
|
||||||
issue_number: prNumber,
|
issue_number: resolvedPrNumber,
|
||||||
is_pr: true,
|
is_pr: true,
|
||||||
comment_id: 0,
|
comment_id: commentId ?? 0,
|
||||||
comment_type: "issue",
|
comment_type: "issue",
|
||||||
body: null,
|
body: null,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user