From 94ec7de2caf725bc34af0b2095421bf6b98bb347 Mon Sep 17 00:00:00 2001 From: gentlementlegen Date: Mon, 18 Nov 2024 23:50:22 +0900 Subject: [PATCH] fix(parser): simplify priority label parsing Refactor _parsePriorityLabel method for improved readability. --- src/parser/formatting-evaluator-module.ts | 30 ++++++----------------- 1 file changed, 8 insertions(+), 22 deletions(-) diff --git a/src/parser/formatting-evaluator-module.ts b/src/parser/formatting-evaluator-module.ts index 8cfb98e2..73412b87 100644 --- a/src/parser/formatting-evaluator-module.ts +++ b/src/parser/formatting-evaluator-module.ts @@ -174,33 +174,19 @@ export class FormattingEvaluatorModule extends BaseModule { return { formatting, words }; } - _parsePriorityLabel(labels: GitHubIssue["labels"] | undefined): number { - // Has to default to 1 in case there is no priority label - let taskPriorityEstimate = 1; + _parsePriorityLabel(labels: GitHubIssue["labels"] | undefined) { if (!labels) return 1; - for (const label of labels) { - let priorityLabel = ""; - if (typeof label === "string") { - priorityLabel = label; - } else { - priorityLabel = label.name ?? ""; - } - if (priorityLabel.startsWith("Priority:")) { - const matched = priorityLabel.match(/Priority: (\d+)/i); - if (!matched) { - return 0; - } - - const urgency = matched[1]; - taskPriorityEstimate = Number(urgency); - } + for (const label of labels) { + const priorityLabel = typeof label === "string" ? label : (label.name ?? ""); + const matched = priorityLabel.match(/^Priority:\s*(\d+)/i); - if (taskPriorityEstimate) { - break; + if (matched) { + const urgency = Number(matched[1]); + if (urgency) return urgency; } } - return taskPriorityEstimate; + return 1; } }