diff --git a/src/helpers/label-price-extractor.ts b/src/helpers/label-price-extractor.ts index 28c1ee65..11f13c65 100644 --- a/src/helpers/label-price-extractor.ts +++ b/src/helpers/label-price-extractor.ts @@ -20,3 +20,45 @@ export function getSortedPrices(labels: GitHubIssue["labels"] | undefined) { } return sortedPriceLabels; } + +export function parsePriorityLabel( + labels: ( + | string + | { + id?: number; + node_id?: string; + url?: string; + name?: string; + description?: string | null; + color?: string | null; + default?: boolean; + } + )[] +): number { + let taskPriorityEstimate = 0; + + 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/content-evaluator-module.ts b/src/parser/content-evaluator-module.ts index 877d5c32..83fbd82c 100644 --- a/src/parser/content-evaluator-module.ts +++ b/src/parser/content-evaluator-module.ts @@ -19,6 +19,7 @@ import { Relevances, } from "../types/content-evaluator-module-type"; import { GithubCommentScore, Module, Result } from "./processor"; +import { parsePriorityLabel } from "../helpers/label-price-extractor"; /** * Evaluates and rates comments. @@ -73,9 +74,12 @@ export class ContentEvaluatorModule implements Module { const currentElement = result[key]; const comments = currentElement.comments ?? []; const specificationBody = data.self?.body; + const issueLabels = data.self?.labels; + const priority = issueLabels ? parsePriorityLabel(issueLabels) : undefined; + if (specificationBody && comments.length) { promises.push( - this._processComment(comments, specificationBody, allComments).then( + this._processComment(comments, priority, specificationBody, allComments).then( (commentsWithScore) => (currentElement.comments = commentsWithScore) ) ); @@ -99,7 +103,12 @@ export class ContentEvaluatorModule implements Module { return reward; } - async _processComment(comments: Readonly[], specificationBody: string, allComments: AllComments) { + async _processComment( + comments: Readonly[], + priority: number | undefined, + specificationBody: string, + allComments: AllComments + ) { const commentsWithScore: GithubCommentScore[] = [...comments]; const { commentsToEvaluate, prCommentsToEvaluate } = this._splitCommentsByPrompt(commentsWithScore); @@ -127,7 +136,7 @@ export class ContentEvaluatorModule implements Module { currentComment.score = { ...(currentComment.score || { multiplier: 0 }), relevance: new Decimal(currentRelevance).toNumber(), - reward: currentReward.toNumber(), + reward: currentReward.mul(priority ?? 1).toNumber(), }; }