mirror of
https://github.com/actions/labeler.git
synced 2025-12-12 12:37:48 +00:00
Rename checkGlobs to checkMatchConfigs and check each property
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import {checkGlobs, MatchConfig} from '../src/labeler';
|
import {checkMatchConfigs, MatchConfig} from '../src/labeler';
|
||||||
|
|
||||||
import * as core from '@actions/core';
|
import * as core from '@actions/core';
|
||||||
|
|
||||||
@@ -16,17 +16,17 @@ const matchConfig = [
|
|||||||
{'changed-files': [{any: ['*.txt']}]}
|
{'changed-files': [{any: ['*.txt']}]}
|
||||||
] as unknown as MatchConfig[];
|
] as unknown as MatchConfig[];
|
||||||
|
|
||||||
describe('checkGlobs', () => {
|
describe('checkMatchConfigs', () => {
|
||||||
it('returns true when our pattern does match changed files', () => {
|
it('returns true when our pattern does match changed files', () => {
|
||||||
const changedFiles = ['foo.txt', 'bar.txt'];
|
const changedFiles = ['foo.txt', 'bar.txt'];
|
||||||
const result = checkGlobs(changedFiles, matchConfig);
|
const result = checkMatchConfigs(changedFiles, matchConfig);
|
||||||
|
|
||||||
expect(result).toBeTruthy();
|
expect(result).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('returns false when our pattern does not match changed files', () => {
|
it('returns false when our pattern does not match changed files', () => {
|
||||||
const changedFiles = ['foo.docx'];
|
const changedFiles = ['foo.docx'];
|
||||||
const result = checkGlobs(changedFiles, matchConfig);
|
const result = checkMatchConfigs(changedFiles, matchConfig);
|
||||||
|
|
||||||
expect(result).toBeFalsy();
|
expect(result).toBeFalsy();
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ export async function run() {
|
|||||||
const labelsToRemove: string[] = [];
|
const labelsToRemove: string[] = [];
|
||||||
for (const [label, configs] of labelConfigs.entries()) {
|
for (const [label, configs] of labelConfigs.entries()) {
|
||||||
core.debug(`processing ${label}`);
|
core.debug(`processing ${label}`);
|
||||||
if (checkGlobs(changedFiles, configs)) {
|
if (checkMatchConfigs(changedFiles, configs)) {
|
||||||
labels.push(label);
|
labels.push(label);
|
||||||
} else if (pullRequest.labels.find(l => l.name === label)) {
|
} else if (pullRequest.labels.find(l => l.name === label)) {
|
||||||
labelsToRemove.push(label);
|
labelsToRemove.push(label);
|
||||||
@@ -205,18 +205,18 @@ function printPattern(matcher: Minimatch): string {
|
|||||||
return (matcher.negate ? '!' : '') + matcher.pattern;
|
return (matcher.negate ? '!' : '') + matcher.pattern;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function checkGlobs(
|
export function checkMatchConfigs(
|
||||||
changedFiles: string[],
|
changedFiles: string[],
|
||||||
globs: MatchConfig[]
|
matchConfigs: MatchConfig[]
|
||||||
): boolean {
|
): boolean {
|
||||||
for (const glob of globs) {
|
for (const config of matchConfigs) {
|
||||||
core.debug(` checking pattern ${JSON.stringify(glob)}`);
|
core.debug(` checking pattern ${JSON.stringify(config)}`);
|
||||||
const matchConfig = toMatchConfig(glob);
|
const matchConfig = toMatchConfig(config);
|
||||||
if (checkMatch(changedFiles, matchConfig)) {
|
if (!checkMatch(changedFiles, matchConfig)) {
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function isMatch(changedFile: string, matchers: Minimatch[]): boolean {
|
function isMatch(changedFile: string, matchers: Minimatch[]): boolean {
|
||||||
|
|||||||
Reference in New Issue
Block a user