mirror of
https://github.com/actions/labeler.git
synced 2025-12-11 12:07:32 +00:00
Update tests and build
This commit is contained in:
@@ -54,9 +54,9 @@ describe('checkAnyChangedFiles', () => {
|
|||||||
describe('when all globs do not match any of the files that have changed', () => {
|
describe('when all globs do not match any of the files that have changed', () => {
|
||||||
const globs = ['*.txt', '*.md'];
|
const globs = ['*.txt', '*.md'];
|
||||||
|
|
||||||
it('returns false', () => {
|
it('returns true', () => {
|
||||||
const result = checkAnyChangedFiles(changedFiles, globs);
|
const result = checkAnyChangedFiles(changedFiles, globs);
|
||||||
expect(result).toBe(false);
|
expect(result).toBe(true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
18
dist/index.js
vendored
18
dist/index.js
vendored
@@ -186,7 +186,19 @@ exports.toChangedFilesMatchConfig = toChangedFilesMatchConfig;
|
|||||||
function printPattern(matcher) {
|
function printPattern(matcher) {
|
||||||
return (matcher.negate ? '!' : '') + matcher.pattern;
|
return (matcher.negate ? '!' : '') + matcher.pattern;
|
||||||
}
|
}
|
||||||
function isMatch(changedFile, matchers) {
|
function isAnyMatch(changedFile, matchers) {
|
||||||
|
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, matchers) {
|
||||||
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)}`);
|
||||||
@@ -201,7 +213,7 @@ function isMatch(changedFile, matchers) {
|
|||||||
function checkAnyChangedFiles(changedFiles, globs) {
|
function checkAnyChangedFiles(changedFiles, globs) {
|
||||||
const matchers = globs.map(g => new minimatch_1.Minimatch(g));
|
const matchers = globs.map(g => new minimatch_1.Minimatch(g));
|
||||||
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;
|
||||||
}
|
}
|
||||||
@@ -213,7 +225,7 @@ exports.checkAnyChangedFiles = checkAnyChangedFiles;
|
|||||||
function checkAllChangedFiles(changedFiles, globs) {
|
function checkAllChangedFiles(changedFiles, globs) {
|
||||||
const matchers = globs.map(g => new minimatch_1.Minimatch(g));
|
const matchers = globs.map(g => new minimatch_1.Minimatch(g));
|
||||||
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