chore: merge branch push/create/delete code

This commit is contained in:
shiftinv 2022-10-21 19:43:36 +02:00
parent a69a51edc6
commit 452482513f
1 changed files with 20 additions and 24 deletions

View File

@ -69,36 +69,32 @@ export default async function filter(
return "bot";
}
// ignore branch/tag push
const refMatch = /^refs\/([^\/]+)\/(.+)$/.exec(json.ref);
if (event === "push" && refMatch) {
// check if branch is allowed
if (
refMatch[1] == "heads" && config.allowBranches !== undefined &&
!config.allowBranches.includes(refMatch[2])
) {
return `branch '${refMatch[2]}' not in ${JSON.stringify(config.allowBranches)}`;
}
// check if it's a tag
if (refMatch[1] == "tags" && config.hideTags === true) {
return `tag '${refMatch[2]}'`;
let refType: "branch" | "tag" | undefined;
let ref: string | undefined;
if (event === "push") {
// ignore branch/tag push
const refMatch = /^refs\/([^\/]+)\/(.+)$/.exec(json.ref);
if (refMatch) {
refType = refMatch[1] === "heads"
? "branch"
: (refMatch[1] == "tags" ? "tag" : undefined);
ref = refMatch[2];
}
} else if (["create", "delete"].includes(event)) {
// ignore creation/deletion of branch/tag
refType = json.ref_type;
ref = json.ref;
}
// ignore creation/deletion of branch/tag
if (["create", "delete"].includes(event)) {
// check if branch is allowed
if (refType && ref) {
if (
json.ref_type === "branch" && config.allowBranches !== undefined &&
!config.allowBranches.includes(json.ref)
refType == "branch" && config.allowBranches !== undefined &&
!config.allowBranches.includes(ref)
) {
return `branch '${json.ref}' not in ${JSON.stringify(config.allowBranches)}`;
return `branch '${ref}' not in ${JSON.stringify(config.allowBranches)}`;
}
// check if it's a tag
if (json.ref_type == "tag" && config.hideTags === true) {
return `tag '${json.ref}'`;
if (refType == "tag" && config.hideTags === true) {
return `tag '${ref}'`;
}
}