2022-09-02 23:35:09 +00:00
|
|
|
import { UrlConfig } from "./types.d.ts";
|
|
|
|
|
|
|
|
export default function filter(headers: Headers, json: any, config: UrlConfig): string | null {
|
2022-09-03 00:39:36 +00:00
|
|
|
const event = headers.get("x-github-event") || "unknown";
|
|
|
|
if (["status", "pull_request_review_thread"].includes(event)) {
|
|
|
|
return event;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (
|
|
|
|
event === "pull_request" && json.action &&
|
|
|
|
!["opened", "closed", "reopened"].includes(json.action)
|
|
|
|
) {
|
|
|
|
return "no-op PR event";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (
|
|
|
|
event === "issues" && json.action &&
|
|
|
|
!["opened", "deleted", "closed", "reopened", "transferred"].includes(json.action)
|
|
|
|
) {
|
|
|
|
return "no-op issue event";
|
|
|
|
}
|
|
|
|
|
2022-09-02 23:35:09 +00:00
|
|
|
const login: string | undefined = json.sender?.login?.toLowerCase();
|
|
|
|
if (
|
|
|
|
login &&
|
|
|
|
["coveralls[bot]", "netlify[bot]", "pre-commit-ci[bot]"].some((n) => login.includes(n))
|
|
|
|
) {
|
|
|
|
return "bot";
|
|
|
|
}
|
|
|
|
|
|
|
|
const refMatch = /^refs\/([^\/]+)\/(.+)$/.exec(json.ref);
|
|
|
|
if (event === "push" && refMatch) {
|
|
|
|
// check if branch is allowed
|
|
|
|
if (
|
2022-09-03 00:30:04 +00:00
|
|
|
refMatch[1] == "heads" && config.allowBranches !== undefined &&
|
|
|
|
!config.allowBranches.includes(refMatch[2])
|
2022-09-02 23:35:09 +00:00
|
|
|
) {
|
2022-09-03 00:30:04 +00:00
|
|
|
return `branch '${refMatch[2]}' not in ${JSON.stringify(config.allowBranches)}`;
|
2022-09-02 23:35:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// check if it's a tag
|
2022-09-03 00:30:04 +00:00
|
|
|
if (refMatch[1] == "tags" && config.hideTags === true) {
|
2022-09-02 23:35:09 +00:00
|
|
|
return "tag";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|