From a95feefaf835a50942a08b6c9a61be0b537a2ebc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=85=E8=86=80?= Date: Fri, 23 Oct 2026 23:22:00 +0800 Subject: [PATCH] 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. --- server/lib/formatters/index.ts | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/server/lib/formatters/index.ts b/server/lib/formatters/index.ts index 2ab1206..1b87e5b 100644 --- a/server/lib/formatters/index.ts +++ b/server/lib/formatters/index.ts @@ -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; + } }