Have a single isMatch for checking changed files

This commit is contained in:
Josh Dales
2023-04-13 14:38:41 -04:00
parent 7f169bc0f2
commit d4d4a104a2

View File

@@ -49,21 +49,7 @@ function printPattern(matcher: Minimatch): string {
return (matcher.negate ? '!' : '') + matcher.pattern; return (matcher.negate ? '!' : '') + matcher.pattern;
} }
function isAnyMatch(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)}`);
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 {
core.debug(` matching patterns against file ${changedFile}`); core.debug(` matching patterns against file ${changedFile}`);
for (const matcher of matchers) { for (const matcher of matchers) {
core.debug(` - ${printPattern(matcher)}`); core.debug(` - ${printPattern(matcher)}`);
@@ -83,7 +69,7 @@ export function checkAnyChangedFiles(
): boolean { ): boolean {
const matchers = globs.map(g => new Minimatch(g)); const matchers = globs.map(g => new Minimatch(g));
for (const changedFile of changedFiles) { for (const changedFile of changedFiles) {
if (isAnyMatch(changedFile, matchers)) { if (isMatch(changedFile, matchers)) {
core.debug(` "any" patterns matched against ${changedFile}`); core.debug(` "any" patterns matched against ${changedFile}`);
return true; return true;
} }
@@ -99,7 +85,7 @@ export function checkAllChangedFiles(
): boolean { ): boolean {
const matchers = globs.map(g => new Minimatch(g)); const matchers = globs.map(g => new Minimatch(g));
for (const changedFile of changedFiles) { for (const changedFile of changedFiles) {
if (!isAllMatch(changedFile, matchers)) { if (!isMatch(changedFile, matchers)) {
core.debug(` "all" patterns did not match against ${changedFile}`); core.debug(` "all" patterns did not match against ${changedFile}`);
return false; return false;
} }