chore: add more comments

This commit is contained in:
shiftinv 2022-09-03 16:48:28 +02:00
parent 1dfa4a6306
commit 32d7b66dad
1 changed files with 7 additions and 0 deletions

View File

@ -2,10 +2,13 @@ import { UrlConfig } from "./types.d.ts";
export default function filter(headers: Headers, json: any, config: UrlConfig): string | null {
const event = headers.get("x-github-event") || "unknown";
// ignore events that Discord won't render anyway
if (["status", "pull_request_review_thread"].includes(event)) {
return event;
}
// ignore all PR actions except "opened", "closed", "reopened"
if (
event === "pull_request" && json.action &&
!["opened", "closed", "reopened"].includes(json.action)
@ -13,6 +16,7 @@ export default function filter(headers: Headers, json: any, config: UrlConfig):
return "no-op PR action";
}
// ignore all issue actions except "opened", "deleted", "closed", "reopened", "transferred"
if (
event === "issues" && json.action &&
!["opened", "deleted", "closed", "reopened", "transferred"].includes(json.action)
@ -20,6 +24,7 @@ export default function filter(headers: Headers, json: any, config: UrlConfig):
return "no-op issue action";
}
// ignore some PR review actions
if (event === "pull_request_review") {
// ignore edit/dismiss actions
if (json.action !== "submitted") return "no-op PR review action";
@ -27,6 +32,7 @@ export default function filter(headers: Headers, json: any, config: UrlConfig):
else if (json.review?.state === "commented" && !json.review?.body) return "empty PR review";
}
// ignore bots
const login: string | undefined = json.sender?.login?.toLowerCase();
if (
login &&
@ -35,6 +41,7 @@ export default function filter(headers: Headers, json: any, config: UrlConfig):
return "bot";
}
// ignore branch/tag if configured
const refMatch = /^refs\/([^\/]+)\/(.+)$/.exec(json.ref);
if (event === "push" && refMatch) {
// check if branch is allowed