diff --git a/__tests__/fixtures/not_supported.yml b/__tests__/fixtures/not_supported.yml new file mode 100644 index 00000000..cb42984b --- /dev/null +++ b/__tests__/fixtures/not_supported.yml @@ -0,0 +1,2 @@ +label: + - unknown-check: 'this-check-is-not-supported' diff --git a/__tests__/labeler.test.ts b/__tests__/labeler.test.ts index 10ba96db..28768651 100644 --- a/__tests__/labeler.test.ts +++ b/__tests__/labeler.test.ts @@ -17,17 +17,18 @@ describe('toMatchConfig', () => { 'head-branch': ['testing-head'], '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', () => { const result = toMatchConfig(config); - expect(result).toEqual({ - changedFiles: { - all: ['testing-all'], - any: ['testing-any'] - }, - headBranch: ['testing-head'], - baseBranch: ['testing-base'] - }); + expect(result).toEqual(expected); }); 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', () => { const result = toMatchConfig(config); - expect(result).toEqual({ - changedFiles: { - all: ['testing-all'], - any: ['testing-any'] - }, - headBranch: ['testing-head'], - baseBranch: ['testing-base'] - }); + expect(result).toEqual(expected); }); }); }); diff --git a/__tests__/main.test.ts b/__tests__/main.test.ts index fd21ca20..240b1ed9 100644 --- a/__tests__/main.test.ts +++ b/__tests__/main.test.ts @@ -16,7 +16,8 @@ const getPullMock = jest.spyOn(gh.rest.pulls, 'get'); const yamlFixtures = { '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()); @@ -48,6 +49,14 @@ describe('run', () => { 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 () => { const mockInput = { 'repo-token': 'foo', diff --git a/src/labeler.ts b/src/labeler.ts index aeca6470..ece526cb 100644 --- a/src/labeler.ts +++ b/src/labeler.ts @@ -151,6 +151,10 @@ export function checkMatchConfigs( } function checkMatch(changedFiles: string[], matchConfig: MatchConfig): boolean { + if (!Object.keys(matchConfig).length) { + return false; + } + if (matchConfig.changedFiles?.all) { if (!checkAll(changedFiles, matchConfig.changedFiles.all)) { return false;