generated from ubiquity/ts-template
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: simplify and handle label lint error
- Loading branch information
Showing
1 changed file
with
10 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,17 @@ | ||
import { GitHubIssue } from "../github-types"; | ||
|
||
export function sortIssuesByPriority(issues: GitHubIssue[]) { | ||
return issues.sort((a, b) => { | ||
const priorityRegex = /Priority: (\d+)/; | ||
const aPriorityMatch = | ||
a.labels.find((label): label is { name: string } => typeof label === "object" && label !== null && "name" in label && priorityRegex.test(label.name)) | ||
?.name || "No Priority"; | ||
const bPriorityMatch = | ||
b.labels.find((label): label is { name: string } => typeof label === "object" && label !== null && "name" in label && priorityRegex.test(label.name)) | ||
?.name || "No Priority"; | ||
|
||
const priorityA = aPriorityMatch.match(priorityRegex); | ||
const priorityB = bPriorityMatch.match(priorityRegex); | ||
const priorityRegex = /Priority: (\d+)/; | ||
|
||
const aPriority = priorityA && priorityA[1] ? parseInt(priorityA[1], 10) : 0; | ||
const bPriority = priorityB && priorityB[1] ? parseInt(priorityB[1], 10) : 0; | ||
return issues.sort((a, b) => { | ||
function getPriority(issue: GitHubIssue) { | ||
const priorityLabel = issue.labels.find( | ||
(label): label is { name: string } => typeof label === "object" && "name" in label && typeof label.name === "string" && priorityRegex.test(label.name) | ||
); | ||
const match = priorityLabel?.name.match(priorityRegex); | ||
return match ? parseInt(match[1], 10) : -1; | ||
} | ||
|
||
return bPriority - aPriority; | ||
return getPriority(b) - getPriority(a); | ||
}); | ||
} |