From 613b00b5fe2c2c4f8974df7c0d4ad415ee9109b6 Mon Sep 17 00:00:00 2001 From: Adam Azarchs Date: Wed, 11 Jan 2023 14:37:37 -0800 Subject: [PATCH 1/2] fix: correct reading of sync-labels input. Contrary to the assumptions made in the unit tests, core.getInput always returns a string, and !!'false' is true. Also updates the unit test to reduce changes of regressions by ensuring that the mocked getInput returns a string, as it would in production. Fixes https://github.com/actions/labeler/issues/112 Make sure test catches regressions. --- __tests__/main.test.ts | 18 ++++++++++++++---- dist/index.js | 2 +- src/labeler.ts | 2 +- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/__tests__/main.test.ts b/__tests__/main.test.ts index e886a02d4..6a969e70b 100644 --- a/__tests__/main.test.ts +++ b/__tests__/main.test.ts @@ -48,15 +48,20 @@ describe('run', () => { }); it('(with sync-labels: true) it deletes preexisting PR labels that no longer match the glob pattern', async () => { - let mockInput = { + const mockInput: {[key: string]: string} = { 'repo-token': 'foo', 'configuration-path': 'bar', - 'sync-labels': true + 'sync-labels': 'true' }; jest .spyOn(core, 'getInput') .mockImplementation((name: string, ...opts) => mockInput[name]); + jest + .spyOn(core, 'getBooleanInput') + .mockImplementation( + (name: string, ...opts) => mockInput[name] === 'true' + ); usingLabelerConfigYaml('only_pdfs.yml'); mockGitHubResponseChangedFiles('foo.txt'); @@ -79,15 +84,20 @@ describe('run', () => { }); it('(with sync-labels: false) it issues no delete calls even when there are preexisting PR labels that no longer match the glob pattern', async () => { - let mockInput = { + const mockInput: {[key: string]: string} = { 'repo-token': 'foo', 'configuration-path': 'bar', - 'sync-labels': false + 'sync-labels': 'false' }; jest .spyOn(core, 'getInput') .mockImplementation((name: string, ...opts) => mockInput[name]); + jest + .spyOn(core, 'getBooleanInput') + .mockImplementation( + (name: string, ...opts) => mockInput[name] === 'true' + ); usingLabelerConfigYaml('only_pdfs.yml'); mockGitHubResponseChangedFiles('foo.txt'); diff --git a/dist/index.js b/dist/index.js index 4b521af64..c793d4799 100644 --- a/dist/index.js +++ b/dist/index.js @@ -49,7 +49,7 @@ function run() { try { const token = core.getInput('repo-token', { required: true }); const configPath = core.getInput('configuration-path', { required: true }); - const syncLabels = !!core.getInput('sync-labels', { required: false }); + const syncLabels = core.getBooleanInput('sync-labels', { required: false }); const prNumber = getPrNumber(); if (!prNumber) { console.log('Could not get pull request number from context, exiting'); diff --git a/src/labeler.ts b/src/labeler.ts index b33073adc..65e936dde 100644 --- a/src/labeler.ts +++ b/src/labeler.ts @@ -15,7 +15,7 @@ export async function run() { try { const token = core.getInput('repo-token', {required: true}); const configPath = core.getInput('configuration-path', {required: true}); - const syncLabels = !!core.getInput('sync-labels', {required: false}); + const syncLabels = core.getBooleanInput('sync-labels'); const prNumber = getPrNumber(); if (!prNumber) { From b6ad3245670827876c199cc37a6d6ca7801c8dfc Mon Sep 17 00:00:00 2001 From: Adam Azarchs Date: Thu, 26 Jan 2023 13:07:19 -0800 Subject: [PATCH 2/2] Rebuild dist/index.js. --- dist/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dist/index.js b/dist/index.js index c793d4799..cff9847e6 100644 --- a/dist/index.js +++ b/dist/index.js @@ -49,7 +49,7 @@ function run() { try { const token = core.getInput('repo-token', { required: true }); const configPath = core.getInput('configuration-path', { required: true }); - const syncLabels = core.getBooleanInput('sync-labels', { required: false }); + const syncLabels = core.getBooleanInput('sync-labels'); const prNumber = getPrNumber(); if (!prNumber) { console.log('Could not get pull request number from context, exiting');