Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/get-inputs/get-pr-numbers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Comment on lines 17 to +19
core.warning(`'${prNumber}' is not a valid pull request number`);
continue;
}
Expand Down
Loading