mirror of
https://github.com/actions/labeler.git
synced 2025-12-13 04:57:21 +00:00
General refactoring
This commit is contained in:
28
src/get-inputs/get-pr-numbers.ts
Normal file
28
src/get-inputs/get-pr-numbers.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import * as core from '@actions/core';
|
||||
import * as github from '@actions/github';
|
||||
|
||||
const getPrNumberFromContext = () =>
|
||||
github.context.payload.pull_request?.number;
|
||||
|
||||
export const getPrNumbers = (): number[] => {
|
||||
const prInput = core.getMultilineInput('pr-number');
|
||||
|
||||
if (!prInput?.length) {
|
||||
return [getPrNumberFromContext()].filter(Boolean) as number[];
|
||||
}
|
||||
|
||||
const result: number[] = [];
|
||||
|
||||
for (const line of prInput) {
|
||||
const prNumber = parseInt(line, 10);
|
||||
|
||||
if (isNaN(prNumber) && prNumber <= 0) {
|
||||
core.warning(`'${prNumber}' is not a valid pull request number`);
|
||||
continue;
|
||||
}
|
||||
|
||||
result.push(prNumber);
|
||||
}
|
||||
|
||||
return result;
|
||||
};
|
||||
Reference in New Issue
Block a user