From d4d4a104a2813d607be021c8fa4ad51d72906c35 Mon Sep 17 00:00:00 2001 From: Josh Dales Date: Thu, 13 Apr 2023 14:38:41 -0400 Subject: [PATCH] Have a single isMatch for checking changed files --- src/changedFiles.ts | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/src/changedFiles.ts b/src/changedFiles.ts index cd83f3d6..816d51dd 100644 --- a/src/changedFiles.ts +++ b/src/changedFiles.ts @@ -49,21 +49,7 @@ function printPattern(matcher: Minimatch): string { return (matcher.negate ? '!' : '') + matcher.pattern; } -function isAnyMatch(changedFile: string, matchers: Minimatch[]): boolean { - core.debug(` matching patterns against file ${changedFile}`); - for (const matcher of matchers) { - core.debug(` - ${printPattern(matcher)}`); - if (matcher.match(changedFile)) { - core.debug(` ${printPattern(matcher)} matched`); - return true; - } - } - - core.debug(` no patterns matched`); - return false; -} - -function isAllMatch(changedFile: string, matchers: Minimatch[]): boolean { +function isMatch(changedFile: string, matchers: Minimatch[]): boolean { core.debug(` matching patterns against file ${changedFile}`); for (const matcher of matchers) { core.debug(` - ${printPattern(matcher)}`); @@ -83,7 +69,7 @@ export function checkAnyChangedFiles( ): boolean { const matchers = globs.map(g => new Minimatch(g)); for (const changedFile of changedFiles) { - if (isAnyMatch(changedFile, matchers)) { + if (isMatch(changedFile, matchers)) { core.debug(` "any" patterns matched against ${changedFile}`); return true; } @@ -99,7 +85,7 @@ export function checkAllChangedFiles( ): boolean { const matchers = globs.map(g => new Minimatch(g)); for (const changedFile of changedFiles) { - if (!isAllMatch(changedFile, matchers)) { + if (!isMatch(changedFile, matchers)) { core.debug(` "all" patterns did not match against ${changedFile}`); return false; }