From d080448cd65e734b6bbb0cb85a7dfa3d82456df7 Mon Sep 17 00:00:00 2001 From: ishowvel Date: Mon, 11 Nov 2024 06:48:32 +0000 Subject: [PATCH] fix: import error regarding parsePriorityLabel --- src/github-types.ts | 5 ---- src/helpers/label-price-extractor.ts | 31 +-------------------- src/parser/formatting-evaluator-module.ts | 33 +++++++++++++++++++++-- 3 files changed, 32 insertions(+), 37 deletions(-) diff --git a/src/github-types.ts b/src/github-types.ts index 7ec545bb..dd61903e 100644 --- a/src/github-types.ts +++ b/src/github-types.ts @@ -1,11 +1,6 @@ import { RestEndpointMethodTypes } from "@octokit/rest"; export type GitHubIssue = RestEndpointMethodTypes["issues"]["get"]["response"]["data"]; -export type GitHubIssueLabel = Partial< - Omit -> & { - color?: string | null; -}; export type GitHubPullRequest = RestEndpointMethodTypes["pulls"]["get"]["response"]["data"]; export type GitHubIssueComment = RestEndpointMethodTypes["issues"]["listComments"]["response"]["data"][0] & { isMinimized?: boolean; diff --git a/src/helpers/label-price-extractor.ts b/src/helpers/label-price-extractor.ts index 3328cb19..28c1ee65 100644 --- a/src/helpers/label-price-extractor.ts +++ b/src/helpers/label-price-extractor.ts @@ -1,4 +1,4 @@ -import { GitHubIssue, GitHubIssueLabel } from "../github-types"; +import { GitHubIssue } from "../github-types"; export function getSortedPrices(labels: GitHubIssue["labels"] | undefined) { if (!labels) return []; @@ -20,32 +20,3 @@ export function getSortedPrices(labels: GitHubIssue["labels"] | undefined) { } return sortedPriceLabels; } - -export function parsePriorityLabel(labels: (string | GitHubIssueLabel)[] | undefined): number { - let taskPriorityEstimate = 0; - 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); - } - - if (taskPriorityEstimate) { - break; - } - } - - return taskPriorityEstimate; -} diff --git a/src/parser/formatting-evaluator-module.ts b/src/parser/formatting-evaluator-module.ts index f86c1ba7..a00c1736 100644 --- a/src/parser/formatting-evaluator-module.ts +++ b/src/parser/formatting-evaluator-module.ts @@ -12,8 +12,8 @@ import { IssueActivity } from "../issue-activity"; import { BaseModule } from "../types/module"; import { GithubCommentScore, Result, WordResult } from "../types/results"; import { typeReplacer } from "../helpers/result-replacer"; -import { parsePriorityLabel } from "../helpers/label-price-extractor"; import { ContextPlugin } from "../types/plugin-input"; +import { GitHubIssue } from "../github-types"; interface Multiplier { multiplier: number; @@ -68,7 +68,7 @@ export class FormattingEvaluatorModule extends BaseModule { const { formatting, words } = this._getFormattingScore(comment); const multiplierFactor = this._multipliers?.[comment.type] ?? { multiplier: 0 }; const formattingTotal = this._calculateFormattingTotal(formatting, words, multiplierFactor).toDecimalPlaces(2); - const priority = parsePriorityLabel(data.self?.labels); + const priority = this._parsePriorityLabel(data.self?.labels); const reward = (comment.score?.reward ? formattingTotal.add(comment.score.reward) : formattingTotal).toNumber(); comment.score = { ...comment.score, @@ -173,4 +173,33 @@ export class FormattingEvaluatorModule extends BaseModule { const words = this._countWordsFromRegex(htmlElement.textContent ?? "", this._multipliers[commentType]?.wordValue); return { formatting, words }; } + + _parsePriorityLabel(labels: GitHubIssue["labels"] | undefined): number { + let taskPriorityEstimate = 0; + 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); + } + + if (taskPriorityEstimate) { + break; + } + } + + return taskPriorityEstimate; + } }