From 0db6b493624281bde3d7125c4507884f5cf6dcc3 Mon Sep 17 00:00:00 2001 From: shiftinv Date: Sat, 1 Apr 2023 19:21:08 +0200 Subject: [PATCH] feat: show bot pushes on allowed branches --- lib/filter.ts | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/lib/filter.ts b/lib/filter.ts index 0487d70..a18ca38 100644 --- a/lib/filter.ts +++ b/lib/filter.ts @@ -61,16 +61,6 @@ export default async function filter( } } - // ignore bots - if ( - login && - ["coveralls[bot]", "netlify[bot]", "pre-commit-ci[bot]", "dependabot[bot]"].some((n) => - login.includes(n) - ) - ) { - return "bot"; - } - let refType: "branch" | "tag" | undefined; let ref: string | undefined; if (event === "push") { @@ -95,17 +85,31 @@ export default async function filter( return `tag '${ref}' pushed`; } + // true if `allowBranches` is set and the current branch matches it + let isExplicitlyAllowedBranch = false; + if (refType && ref) { - if ( - refType == "branch" && config.allowBranches !== undefined && - !wildcardMatch(config.allowBranches, ref) - ) { - return `branch '${ref}' does not match ${JSON.stringify(config.allowBranches)}`; + if (refType == "branch" && config.allowBranches !== undefined) { + isExplicitlyAllowedBranch = wildcardMatch(config.allowBranches, ref); + if (!isExplicitlyAllowedBranch) { + return `branch '${ref}' does not match ${JSON.stringify(config.allowBranches)}`; + } } if (refType == "tag" && config.hideTags === true) { return `tag '${ref}'`; } } + // ignore bots + if ( + !isExplicitlyAllowedBranch && // show bot pushes on allowed branches + login && + ["coveralls[bot]", "netlify[bot]", "pre-commit-ci[bot]", "dependabot[bot]"].some((n) => + login.includes(n) + ) + ) { + return "bot"; + } + return null; }