mirror of
https://github.com/actions/labeler.git
synced 2025-12-13 04:57:21 +00:00
Add function for checking if any path matches
This commit is contained in:
@@ -49,7 +49,21 @@ function printPattern(matcher: Minimatch): string {
|
|||||||
return (matcher.negate ? '!' : '') + matcher.pattern;
|
return (matcher.negate ? '!' : '') + matcher.pattern;
|
||||||
}
|
}
|
||||||
|
|
||||||
function isMatch(changedFile: string, matchers: Minimatch[]): boolean {
|
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 {
|
||||||
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)}`);
|
||||||
@@ -70,7 +84,7 @@ export function checkAnyChangedFiles(
|
|||||||
const matchers = globs.map(g => new Minimatch(g));
|
const matchers = globs.map(g => new Minimatch(g));
|
||||||
core.debug(` checking "any" patterns`);
|
core.debug(` checking "any" patterns`);
|
||||||
for (const changedFile of changedFiles) {
|
for (const changedFile of changedFiles) {
|
||||||
if (isMatch(changedFile, matchers)) {
|
if (isAnyMatch(changedFile, matchers)) {
|
||||||
core.debug(` "any" patterns matched against ${changedFile}`);
|
core.debug(` "any" patterns matched against ${changedFile}`);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -87,7 +101,7 @@ export function checkAllChangedFiles(
|
|||||||
const matchers = globs.map(g => new Minimatch(g));
|
const matchers = globs.map(g => new Minimatch(g));
|
||||||
core.debug(` checking "all" patterns`);
|
core.debug(` checking "all" patterns`);
|
||||||
for (const changedFile of changedFiles) {
|
for (const changedFile of changedFiles) {
|
||||||
if (!isMatch(changedFile, matchers)) {
|
if (!isAllMatch(changedFile, matchers)) {
|
||||||
core.debug(` "all" patterns did not match against ${changedFile}`);
|
core.debug(` "all" patterns did not match against ${changedFile}`);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user