Skip to content

Commit

Permalink
Have a single isMatch for checking changed files
Browse files Browse the repository at this point in the history
  • Loading branch information
joshdales committed Apr 13, 2023
1 parent 7f169bc commit d4d4a10
Showing 1 changed file with 3 additions and 17 deletions.
20 changes: 3 additions & 17 deletions src/changedFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)}`);
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand Down

0 comments on commit d4d4a10

Please sign in to comment.