Skip to content

Commit

Permalink
fix(parser): simplify priority label parsing
Browse files Browse the repository at this point in the history
Refactor _parsePriorityLabel method for improved readability.
  • Loading branch information
gentlementlegen committed Nov 18, 2024
1 parent 958cff4 commit 94ec7de
Showing 1 changed file with 8 additions and 22 deletions.
30 changes: 8 additions & 22 deletions src/parser/formatting-evaluator-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

0 comments on commit 94ec7de

Please sign in to comment.