diff --git a/lib/filter.ts b/lib/filter.ts index aa0b23d..482b1e2 100644 --- a/lib/filter.ts +++ b/lib/filter.ts @@ -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