diff --git a/__tests__/main.test.ts b/__tests__/main.test.ts index 434db55ec..7ce9796a1 100644 --- a/__tests__/main.test.ts +++ b/__tests__/main.test.ts @@ -441,6 +441,42 @@ describe('run', () => { ); }); + it('(with pr-number: non-numeric value) warns and skips invalid PR numbers', async () => { + configureInput({ + 'repo-token': 'foo', + 'configuration-path': 'bar', + 'pr-number': ['not-a-number'] + }); + + usingLabelerConfigYaml('only_pdfs.yml'); + mockGitHubResponseChangedFiles('foo.pdf'); + + await run(); + + expect(setLabelsMock).toHaveBeenCalledTimes(0); + expect(coreWarningMock).toHaveBeenCalledWith( + `'NaN' is not a valid pull request number` + ); + }); + + it('(with pr-number: negative value) warns and skips negative PR numbers', async () => { + configureInput({ + 'repo-token': 'foo', + 'configuration-path': 'bar', + 'pr-number': ['-5'] + }); + + usingLabelerConfigYaml('only_pdfs.yml'); + mockGitHubResponseChangedFiles('foo.pdf'); + + await run(); + + expect(setLabelsMock).toHaveBeenCalledTimes(0); + expect(coreWarningMock).toHaveBeenCalledWith( + `'-5' is not a valid pull request number` + ); + }); + it('does not add labels to PRs that have no changed files', async () => { usingLabelerConfigYaml('only_pdfs.yml'); mockGitHubResponseChangedFiles(); diff --git a/dist/index.js b/dist/index.js index b7c09fe60..23c5658ee 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1003,7 +1003,7 @@ const getPrNumbers = () => { const result = []; for (const line of prInput) { const prNumber = parseInt(line, 10); - if (isNaN(prNumber) && prNumber <= 0) { + if (isNaN(prNumber) || prNumber <= 0) { core.warning(`'${prNumber}' is not a valid pull request number`); continue; } diff --git a/src/get-inputs/get-pr-numbers.ts b/src/get-inputs/get-pr-numbers.ts index 35324ce5b..a6ae4d9ae 100644 --- a/src/get-inputs/get-pr-numbers.ts +++ b/src/get-inputs/get-pr-numbers.ts @@ -16,7 +16,7 @@ export const getPrNumbers = (): number[] => { for (const line of prInput) { const prNumber = parseInt(line, 10); - if (isNaN(prNumber) && prNumber <= 0) { + if (isNaN(prNumber) || prNumber <= 0) { core.warning(`'${prNumber}' is not a valid pull request number`); continue; }