mirror of
https://github.com/actions/labeler.git
synced 2025-12-13 04:57:21 +00:00
Fix "any" matching when not all globs match (#75)
The previous logic had a bug where the "any" pattern list could match against changed files even when not all globs matched a single changed file. The bug arose individual globs in the "any" list were tested against all changed files individually. Therefore, as long as at least one changed file matched an individual glob in the list, a successful match would be found. The correct behavior is to match all the globs in the list against each individual file. This ensures that is possible to define exlcusions correctly and matched the documented behavior.
This commit is contained in:
67
dist/index.js
vendored
67
dist/index.js
vendored
@@ -4207,6 +4207,9 @@ function toMatchConfig(config) {
|
|||||||
}
|
}
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
|
function printPattern(matcher) {
|
||||||
|
return (matcher.negate ? "!" : "") + matcher.pattern;
|
||||||
|
}
|
||||||
function checkGlobs(changedFiles, globs) {
|
function checkGlobs(changedFiles, globs) {
|
||||||
for (const glob of globs) {
|
for (const glob of globs) {
|
||||||
core.debug(` checking pattern ${JSON.stringify(glob)}`);
|
core.debug(` checking pattern ${JSON.stringify(glob)}`);
|
||||||
@@ -4217,45 +4220,53 @@ function checkGlobs(changedFiles, globs) {
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// equivalent to "Array.some()" but expanded for debugging and clarity
|
function isMatch(changedFile, matchers) {
|
||||||
function checkAny(changedFiles, glob) {
|
core.debug(` matching patterns against file ${changedFile}`);
|
||||||
core.debug(` checking "any" pattern ${glob}`);
|
for (const matcher of matchers) {
|
||||||
const matcher = new minimatch_1.Minimatch(glob);
|
core.debug(` - ${printPattern(matcher)}`);
|
||||||
for (const changedFile of changedFiles) {
|
|
||||||
core.debug(` - ${changedFile}`);
|
|
||||||
if (matcher.match(changedFile)) {
|
|
||||||
core.debug(` ${changedFile} matches`);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
// equivalent to "Array.every()" but expanded for debugging and clarity
|
|
||||||
function checkAll(changedFiles, glob) {
|
|
||||||
core.debug(` checking "all" pattern ${glob}`);
|
|
||||||
const matcher = new minimatch_1.Minimatch(glob);
|
|
||||||
for (const changedFile of changedFiles) {
|
|
||||||
core.debug(` - ${changedFile}`);
|
|
||||||
if (!matcher.match(changedFile)) {
|
if (!matcher.match(changedFile)) {
|
||||||
core.debug(` ${changedFile} did not match`);
|
core.debug(` ${printPattern(matcher)} did not match`);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
core.debug(` all patterns matched`);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
// equivalent to "Array.some()" but expanded for debugging and clarity
|
||||||
|
function checkAny(changedFiles, globs) {
|
||||||
|
const matchers = globs.map(g => new minimatch_1.Minimatch(g));
|
||||||
|
core.debug(` checking "any" patterns`);
|
||||||
|
for (const changedFile of changedFiles) {
|
||||||
|
if (isMatch(changedFile, matchers)) {
|
||||||
|
core.debug(` "any" patterns matched against ${changedFile}`);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
core.debug(` "any" patterns did not match any files`);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// equivalent to "Array.every()" but expanded for debugging and clarity
|
||||||
|
function checkAll(changedFiles, globs) {
|
||||||
|
const matchers = globs.map(g => new minimatch_1.Minimatch(g));
|
||||||
|
core.debug(` checking "all" patterns`);
|
||||||
|
for (const changedFile of changedFiles) {
|
||||||
|
if (!isMatch(changedFile, matchers)) {
|
||||||
|
core.debug(` "all" patterns did not match against ${changedFile}`);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
core.debug(` "all" patterns matched all files`);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
function checkMatch(changedFiles, matchConfig) {
|
function checkMatch(changedFiles, matchConfig) {
|
||||||
if (matchConfig.all !== undefined) {
|
if (matchConfig.all !== undefined) {
|
||||||
for (const glob of matchConfig.all) {
|
if (!checkAll(changedFiles, matchConfig.all)) {
|
||||||
if (!checkAll(changedFiles, glob)) {
|
return false;
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (matchConfig.any !== undefined) {
|
if (matchConfig.any !== undefined) {
|
||||||
for (const glob of matchConfig.any) {
|
if (!checkAny(changedFiles, matchConfig.any)) {
|
||||||
if (!checkAny(changedFiles, glob)) {
|
return false;
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
74
src/main.ts
74
src/main.ts
@@ -135,6 +135,10 @@ function toMatchConfig(config: StringOrMatchConfig): MatchConfig {
|
|||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function printPattern(matcher: IMinimatch): string {
|
||||||
|
return (matcher.negate ? "!" : "") + matcher.pattern;
|
||||||
|
}
|
||||||
|
|
||||||
function checkGlobs(
|
function checkGlobs(
|
||||||
changedFiles: string[],
|
changedFiles: string[],
|
||||||
globs: StringOrMatchConfig[]
|
globs: StringOrMatchConfig[]
|
||||||
@@ -149,50 +153,60 @@ function checkGlobs(
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// equivalent to "Array.some()" but expanded for debugging and clarity
|
function isMatch(changedFile: string, matchers: IMinimatch[]): boolean {
|
||||||
function checkAny(changedFiles: string[], glob: string): boolean {
|
core.debug(` matching patterns against file ${changedFile}`);
|
||||||
core.debug(` checking "any" pattern ${glob}`);
|
for (const matcher of matchers) {
|
||||||
const matcher = new Minimatch(glob);
|
core.debug(` - ${printPattern(matcher)}`);
|
||||||
for (const changedFile of changedFiles) {
|
|
||||||
core.debug(` - ${changedFile}`);
|
|
||||||
if (matcher.match(changedFile)) {
|
|
||||||
core.debug(` ${changedFile} matches`);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// equivalent to "Array.every()" but expanded for debugging and clarity
|
|
||||||
function checkAll(changedFiles: string[], glob: string): boolean {
|
|
||||||
core.debug(` checking "all" pattern ${glob}`);
|
|
||||||
const matcher = new Minimatch(glob);
|
|
||||||
for (const changedFile of changedFiles) {
|
|
||||||
core.debug(` - ${changedFile}`);
|
|
||||||
if (!matcher.match(changedFile)) {
|
if (!matcher.match(changedFile)) {
|
||||||
core.debug(` ${changedFile} did not match`);
|
core.debug(` ${printPattern(matcher)} did not match`);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
core.debug(` all patterns matched`);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// equivalent to "Array.some()" but expanded for debugging and clarity
|
||||||
|
function checkAny(changedFiles: string[], globs: string[]): boolean {
|
||||||
|
const matchers = globs.map(g => new Minimatch(g));
|
||||||
|
core.debug(` checking "any" patterns`);
|
||||||
|
for (const changedFile of changedFiles) {
|
||||||
|
if (isMatch(changedFile, matchers)) {
|
||||||
|
core.debug(` "any" patterns matched against ${changedFile}`);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
core.debug(` "any" patterns did not match any files`);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// equivalent to "Array.every()" but expanded for debugging and clarity
|
||||||
|
function checkAll(changedFiles: string[], globs: string[]): boolean {
|
||||||
|
const matchers = globs.map(g => new Minimatch(g));
|
||||||
|
core.debug(` checking "all" patterns`);
|
||||||
|
for (const changedFile of changedFiles) {
|
||||||
|
if (!isMatch(changedFile, matchers)) {
|
||||||
|
core.debug(` "all" patterns did not match against ${changedFile}`);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
core.debug(` "all" patterns matched all files`);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkMatch(changedFiles: string[], matchConfig: MatchConfig): boolean {
|
function checkMatch(changedFiles: string[], matchConfig: MatchConfig): boolean {
|
||||||
if (matchConfig.all !== undefined) {
|
if (matchConfig.all !== undefined) {
|
||||||
for (const glob of matchConfig.all) {
|
if (!checkAll(changedFiles, matchConfig.all)) {
|
||||||
if (!checkAll(changedFiles, glob)) {
|
return false;
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (matchConfig.any !== undefined) {
|
if (matchConfig.any !== undefined) {
|
||||||
for (const glob of matchConfig.any) {
|
if (!checkAny(changedFiles, matchConfig.any)) {
|
||||||
if (!checkAny(changedFiles, glob)) {
|
return false;
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user