mirror of
https://github.com/actions/labeler.git
synced 2025-12-11 12:07:32 +00:00
Make sure that empty config options don't accidently label things
This commit is contained in:
2
__tests__/fixtures/not_supported.yml
Normal file
2
__tests__/fixtures/not_supported.yml
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
label:
|
||||||
|
- unknown-check: 'this-check-is-not-supported'
|
||||||
@@ -17,17 +17,18 @@ describe('toMatchConfig', () => {
|
|||||||
'head-branch': ['testing-head'],
|
'head-branch': ['testing-head'],
|
||||||
'base-branch': ['testing-base']
|
'base-branch': ['testing-base']
|
||||||
};
|
};
|
||||||
|
const expected: MatchConfig = {
|
||||||
|
changedFiles: {
|
||||||
|
all: ['testing-all'],
|
||||||
|
any: ['testing-any']
|
||||||
|
},
|
||||||
|
headBranch: ['testing-head'],
|
||||||
|
baseBranch: ['testing-base']
|
||||||
|
};
|
||||||
|
|
||||||
it('returns a MatchConfig object with all options', () => {
|
it('returns a MatchConfig object with all options', () => {
|
||||||
const result = toMatchConfig(config);
|
const result = toMatchConfig(config);
|
||||||
expect(result).toEqual<MatchConfig>({
|
expect(result).toEqual(expected);
|
||||||
changedFiles: {
|
|
||||||
all: ['testing-all'],
|
|
||||||
any: ['testing-any']
|
|
||||||
},
|
|
||||||
headBranch: ['testing-head'],
|
|
||||||
baseBranch: ['testing-base']
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('and there are also unexpected options present', () => {
|
describe('and there are also unexpected options present', () => {
|
||||||
@@ -35,14 +36,7 @@ describe('toMatchConfig', () => {
|
|||||||
|
|
||||||
it('does not include the unexpected items in the returned MatchConfig object', () => {
|
it('does not include the unexpected items in the returned MatchConfig object', () => {
|
||||||
const result = toMatchConfig(config);
|
const result = toMatchConfig(config);
|
||||||
expect(result).toEqual<MatchConfig>({
|
expect(result).toEqual(expected);
|
||||||
changedFiles: {
|
|
||||||
all: ['testing-all'],
|
|
||||||
any: ['testing-any']
|
|
||||||
},
|
|
||||||
headBranch: ['testing-head'],
|
|
||||||
baseBranch: ['testing-base']
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -16,7 +16,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')
|
||||||
};
|
};
|
||||||
|
|
||||||
afterAll(() => jest.restoreAllMocks());
|
afterAll(() => jest.restoreAllMocks());
|
||||||
@@ -48,6 +49,14 @@ describe('run', () => {
|
|||||||
expect(addLabelsMock).toHaveBeenCalledTimes(0);
|
expect(addLabelsMock).toHaveBeenCalledTimes(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('does not add a label when no match config options match', async () => {
|
||||||
|
usingLabelerConfigYaml('not_supported.yml');
|
||||||
|
await run();
|
||||||
|
|
||||||
|
expect(addLabelsMock).toHaveBeenCalledTimes(0);
|
||||||
|
expect(removeLabelMock).toHaveBeenCalledTimes(0);
|
||||||
|
});
|
||||||
|
|
||||||
it('(with sync-labels: true) it deletes preexisting PR labels that no longer match the glob pattern', async () => {
|
it('(with sync-labels: true) it deletes preexisting PR labels that no longer match the glob pattern', async () => {
|
||||||
const mockInput = {
|
const mockInput = {
|
||||||
'repo-token': 'foo',
|
'repo-token': 'foo',
|
||||||
|
|||||||
@@ -151,6 +151,10 @@ export function checkMatchConfigs(
|
|||||||
}
|
}
|
||||||
|
|
||||||
function checkMatch(changedFiles: string[], matchConfig: MatchConfig): boolean {
|
function checkMatch(changedFiles: string[], matchConfig: MatchConfig): boolean {
|
||||||
|
if (!Object.keys(matchConfig).length) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (matchConfig.changedFiles?.all) {
|
if (matchConfig.changedFiles?.all) {
|
||||||
if (!checkAll(changedFiles, matchConfig.changedFiles.all)) {
|
if (!checkAll(changedFiles, matchConfig.changedFiles.all)) {
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
Reference in New Issue
Block a user