Skip to content

Commit

Permalink
error handling
Browse files Browse the repository at this point in the history
Signed-off-by: Sachin Panayil <[email protected]>
  • Loading branch information
sachin-panayil committed Dec 23, 2024
1 parent 716ebb5 commit 6410893
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 21 deletions.
21 changes: 11 additions & 10 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -619,12 +619,17 @@ function getPRBody(result) {
`;
}
function cleanLabels(labels) {
const arrayOfLabels = labels.split(",");
const cleanedLabels = [];
arrayOfLabels.forEach((element) => {
cleanedLabels.push(element.trim());
});
return cleanedLabels;
try {
const arrayOfLabels = labels.split(",");
const cleanedLabels = [];
arrayOfLabels.forEach((element) => {
cleanedLabels.push(element.trim());
});
return cleanedLabels;
}
catch (error) {
throw new Error('Invalid label format. See GitHub label documentation: https://docs.github.com/en/issues/using-labels-and-milestones-to-track-work/managing-labels');
}
}
function run(disableRetry) {
return __awaiter(this, void 0, void 0, function* () {
Expand All @@ -651,10 +656,6 @@ function run(disableRetry) {
// verify the label color is a color
if (!/[0-9a-fA-F]{6}/.test(ISSUE_LABEL_COLOR))
throw new Error(`Invalid label color ${ISSUE_LABEL_COLOR}`);
// verify pull request labels are valid
if (PULL_REQUEST_LABELS && !/^[a-zA-Z0-9\-_. ,]+$/.test(PULL_REQUEST_LABELS)) {
throw new Error(`Invalid pull request labels. For label standards, see: https://docs.github.com/en/issues/using-labels-and-milestones-to-track-work/managing-labels`);
}
// override GITHUB_TOKEN and INPUT_GITHUB_TOKEN if INPUT_TOKEN is present
if (TOKEN) {
delete process.env['INPUT_TOKEN'];
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,18 @@ function getPRBody(result: LintResult): string {
}

function cleanLabels(labels: string): string[] {
const arrayOfLabels = labels.split(",")
const cleanedLabels: string[] = []
try {
const arrayOfLabels = labels.split(",")
const cleanedLabels: string[] = []

arrayOfLabels.forEach((element) => {
cleanedLabels.push(element.trim())
})
arrayOfLabels.forEach((element) => {
cleanedLabels.push(element.trim())
})

return cleanedLabels
return cleanedLabels
} catch (error) {
throw new Error('Invalid label format. See GitHub label documentation: https://docs.github.com/en/issues/using-labels-and-milestones-to-track-work/managing-labels')
}
}

export default async function run(disableRetry?: boolean): Promise<void> {
Expand Down Expand Up @@ -110,10 +114,6 @@ export default async function run(disableRetry?: boolean): Promise<void> {
// verify the label color is a color
if (!/[0-9a-fA-F]{6}/.test(ISSUE_LABEL_COLOR))
throw new Error(`Invalid label color ${ISSUE_LABEL_COLOR}`)
// verify pull request labels are valid
if (PULL_REQUEST_LABELS && !/^[a-zA-Z0-9\-_. ,]+$/.test(PULL_REQUEST_LABELS)) {
throw new Error(`Invalid pull request labels. For label standards, see: https://docs.github.com/en/issues/using-labels-and-milestones-to-track-work/managing-labels`)
}
// override GITHUB_TOKEN and INPUT_GITHUB_TOKEN if INPUT_TOKEN is present
if (TOKEN) {
delete process.env['INPUT_TOKEN']
Expand Down

0 comments on commit 6410893

Please sign in to comment.