Add any and all functions for both checks

This commit is contained in:
Josh Dales
2023-03-24 21:44:26 -04:00
parent a9e07ce8ff
commit 3bec9227d1
5 changed files with 73 additions and 37 deletions

View File

@@ -40,7 +40,7 @@ export function getBranchName(branchBase: BranchBase): string | undefined {
}
}
export function checkBranch(
export function checkAnyBranch(
regexps: string[],
branchBase: BranchBase
): boolean {
@@ -63,6 +63,29 @@ export function checkBranch(
return false;
}
export function checkAllBranch(
regexps: string[],
branchBase: BranchBase
): boolean {
const branchName = getBranchName(branchBase);
if (!branchName) {
core.debug(` no branch name`);
return false;
}
core.debug(` checking "branch" pattern against ${branchName}`);
const matchers = regexps.map(regexp => new RegExp(regexp));
for (const matcher of matchers) {
if (!matchBranchPattern(matcher, branchName)) {
core.debug(` "branch" patterns matched against ${branchName}`);
return false;
}
}
core.debug(` "branch" patterns did not match against ${branchName}`);
return true;
}
function matchBranchPattern(matcher: RegExp, branchName: string): boolean {
core.debug(` - ${matcher}`);
if (matcher.test(branchName)) {