mirror of
https://github.com/actions/labeler.git
synced 2025-12-11 12:07:32 +00:00
Better check for empty configs in checkAll
This commit is contained in:
6
__tests__/fixtures/any_and_all.yml
Normal file
6
__tests__/fixtures/any_and_all.yml
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
tests:
|
||||||
|
- any:
|
||||||
|
- head-branch: ['^tests/', '^test/']
|
||||||
|
- changed-files: ['tests/**/*']
|
||||||
|
- all:
|
||||||
|
- changed-files: ['!tests/requirements.txt']
|
||||||
@@ -17,7 +17,8 @@ const getPullMock = jest.spyOn(gh.rest.pulls, 'get');
|
|||||||
const yamlFixtures = {
|
const yamlFixtures = {
|
||||||
'branches.yml': fs.readFileSync('__tests__/fixtures/branches.yml'),
|
'branches.yml': fs.readFileSync('__tests__/fixtures/branches.yml'),
|
||||||
'only_pdfs.yml': fs.readFileSync('__tests__/fixtures/only_pdfs.yml'),
|
'only_pdfs.yml': fs.readFileSync('__tests__/fixtures/only_pdfs.yml'),
|
||||||
'not_supported.yml': fs.readFileSync('__tests__/fixtures/not_supported.yml')
|
'not_supported.yml': fs.readFileSync('__tests__/fixtures/not_supported.yml'),
|
||||||
|
'any_and_all.yml': fs.readFileSync('__tests__/fixtures/any_and_all.yml')
|
||||||
};
|
};
|
||||||
|
|
||||||
afterAll(() => jest.restoreAllMocks());
|
afterAll(() => jest.restoreAllMocks());
|
||||||
@@ -167,9 +168,9 @@ describe('run', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('can support multiple branches by providing an array', async () => {
|
it('adds a label when matching any and all patterns are provided', async () => {
|
||||||
github.context.payload.pull_request!.head = {ref: 'array/123'};
|
usingLabelerConfigYaml('any_and_all.yml');
|
||||||
usingLabelerConfigYaml('branches.yml');
|
mockGitHubResponseChangedFiles('tests/test.ts');
|
||||||
await run();
|
await run();
|
||||||
|
|
||||||
expect(addLabelsMock).toHaveBeenCalledTimes(1);
|
expect(addLabelsMock).toHaveBeenCalledTimes(1);
|
||||||
@@ -177,9 +178,18 @@ describe('run', () => {
|
|||||||
owner: 'monalisa',
|
owner: 'monalisa',
|
||||||
repo: 'helloworld',
|
repo: 'helloworld',
|
||||||
issue_number: 123,
|
issue_number: 123,
|
||||||
labels: ['array-branch']
|
labels: ['tests']
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('does not add a label when not all any and all patterns are matched', async () => {
|
||||||
|
usingLabelerConfigYaml('any_and_all.yml');
|
||||||
|
mockGitHubResponseChangedFiles('tests/requirements.txt');
|
||||||
|
await run();
|
||||||
|
|
||||||
|
expect(addLabelsMock).toHaveBeenCalledTimes(0);
|
||||||
|
expect(removeLabelMock).toHaveBeenCalledTimes(0);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
function usingLabelerConfigYaml(fixtureName: keyof typeof yamlFixtures): void {
|
function usingLabelerConfigYaml(fixtureName: keyof typeof yamlFixtures): void {
|
||||||
|
|||||||
6
dist/index.js
vendored
6
dist/index.js
vendored
@@ -439,7 +439,8 @@ function checkMatch(changedFiles, matchConfig) {
|
|||||||
// equivalent to "Array.some()" but expanded for debugging and clarity
|
// equivalent to "Array.some()" but expanded for debugging and clarity
|
||||||
function checkAny(matchConfigs, changedFiles) {
|
function checkAny(matchConfigs, changedFiles) {
|
||||||
core.debug(` checking "any" patterns`);
|
core.debug(` checking "any" patterns`);
|
||||||
if (!matchConfigs.length) {
|
if (!matchConfigs.length ||
|
||||||
|
!matchConfigs.some(configOption => Object.keys(configOption).length)) {
|
||||||
core.debug(` no "any" patterns to check`);
|
core.debug(` no "any" patterns to check`);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -468,8 +469,7 @@ exports.checkAny = checkAny;
|
|||||||
function checkAll(matchConfigs, changedFiles) {
|
function checkAll(matchConfigs, changedFiles) {
|
||||||
core.debug(` checking "all" patterns`);
|
core.debug(` checking "all" patterns`);
|
||||||
if (!matchConfigs.length ||
|
if (!matchConfigs.length ||
|
||||||
// Make sure that all the configs have keys that we can check for
|
!matchConfigs.some(configOption => Object.keys(configOption).length)) {
|
||||||
!matchConfigs.some(configOption => ALLOWED_CONFIG_KEYS.includes(Object.keys(configOption)[0]))) {
|
|
||||||
core.debug(` no "all" patterns to check`);
|
core.debug(` no "all" patterns to check`);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -225,7 +225,10 @@ export function checkAny(
|
|||||||
changedFiles: string[]
|
changedFiles: string[]
|
||||||
): boolean {
|
): boolean {
|
||||||
core.debug(` checking "any" patterns`);
|
core.debug(` checking "any" patterns`);
|
||||||
if (!matchConfigs.length) {
|
if (
|
||||||
|
!matchConfigs.length ||
|
||||||
|
!matchConfigs.some(configOption => Object.keys(configOption).length)
|
||||||
|
) {
|
||||||
core.debug(` no "any" patterns to check`);
|
core.debug(` no "any" patterns to check`);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -262,10 +265,7 @@ export function checkAll(
|
|||||||
core.debug(` checking "all" patterns`);
|
core.debug(` checking "all" patterns`);
|
||||||
if (
|
if (
|
||||||
!matchConfigs.length ||
|
!matchConfigs.length ||
|
||||||
// Make sure that all the configs have keys that we can check for
|
!matchConfigs.some(configOption => Object.keys(configOption).length)
|
||||||
!matchConfigs.some(configOption =>
|
|
||||||
ALLOWED_CONFIG_KEYS.includes(Object.keys(configOption)[0])
|
|
||||||
)
|
|
||||||
) {
|
) {
|
||||||
core.debug(` no "all" patterns to check`);
|
core.debug(` no "all" patterns to check`);
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
Reference in New Issue
Block a user