From 48606d6e46f99a160c8f8a8a585cdb4d56f7bd6f Mon Sep 17 00:00:00 2001 From: Copilot <198982749+Copilot@users.noreply.github.com> Date: Fri, 15 May 2026 13:12:35 -0400 Subject: [PATCH] Fix logical operator bug in PR number validation (#28) * Initial plan * Fix PR number validation logic: change && to || in isNaN/<=0 check Agent-Logs-Url: https://github.com/chaoscommencer/labeler/sessions/dea87170-64ac-48de-888f-06742907af74 Co-authored-by: chaoscommencer <10524273+chaoscommencer@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: chaoscommencer <10524273+chaoscommencer@users.noreply.github.com> --- __tests__/main.test.ts | 36 ++++++++++++++++++++++++++++++++ dist/index.js | 2 +- src/get-inputs/get-pr-numbers.ts | 2 +- 3 files changed, 38 insertions(+), 2 deletions(-) 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; }