fix(formatter): hide actions on other forges

Action buttons call the GitHub API as the linked user.
Hide them for other forges to avoid operating on a same-named
GitHub repository.
This commit is contained in:
翅膀 committed 2026-10-23 23:22:00 +08:00
1 parent 2e672034d0
commit a95feefaf8
1 file changed
+16 -3
+16 -3
View File
@@ -28,8 +28,21 @@ export function formatEvent(
const ctx: FormatContext = { payload, repo, repoUrl, author, t, showEmoji };
return (
const message =
findFormatter(eventType)?.format(ctx) ??
formatGeneric(eventType, payload, repo, author, t, showEmoji)
);
formatGeneric(eventType, payload, repo, author, t, showEmoji);
// Action buttons (merge / close) call the github.com API with the clicker's
// token: on any other forge they would act on a same-named GitHub repository.
if (message.actions && !isGitHubDotCom(event.provider, repoUrl)) delete message.actions;
return message;
}
function isGitHubDotCom(provider: string | undefined, repoUrl: string | undefined): boolean {
if ((provider ?? "github") !== "github") return false;
if (!repoUrl) return true;
try {
return new URL(repoUrl).hostname.toLowerCase() === "github.com";
} catch {
return false;
}
}