mirror of
https://github.com/Elysola/WebHooker.git
synced 2026-11-20 17:13:49 +00:00
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:
1 parent
2e672034d0
commit
a95feefaf8
1 file changed
+16
-3
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user