Skip to content

Commit

Permalink
fix: import error regarding parsePriorityLabel
Browse files Browse the repository at this point in the history
  • Loading branch information
ishowvel committed Nov 11, 2024
1 parent 4bc1ee6 commit d080448
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 37 deletions.
5 changes: 0 additions & 5 deletions src/github-types.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import { RestEndpointMethodTypes } from "@octokit/rest";

export type GitHubIssue = RestEndpointMethodTypes["issues"]["get"]["response"]["data"];
export type GitHubIssueLabel = Partial<
Omit<RestEndpointMethodTypes["issues"]["listLabelsForRepo"]["response"]["data"][0], "color">
> & {
color?: string | null;
};
export type GitHubPullRequest = RestEndpointMethodTypes["pulls"]["get"]["response"]["data"];
export type GitHubIssueComment = RestEndpointMethodTypes["issues"]["listComments"]["response"]["data"][0] & {
isMinimized?: boolean;
Expand Down
31 changes: 1 addition & 30 deletions src/helpers/label-price-extractor.ts
Original file line number Diff line number Diff line change
@@ -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 [];
Expand All @@ -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;
}
33 changes: 31 additions & 2 deletions src/parser/formatting-evaluator-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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;
}
}

0 comments on commit d080448

Please sign in to comment.