@kitlangton/ghui 0.1.6 → 0.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.env.example +4 -0
- package/package.json +1 -1
- package/src/App.tsx +221 -809
- package/src/config.ts +17 -8
- package/src/domain.ts +17 -0
- package/src/index.tsx +1 -0
- package/src/observability.ts +46 -0
- package/src/services/CommandRunner.ts +6 -1
- package/src/services/GitHubService.ts +161 -14
- package/src/ui/FooterHints.tsx +145 -0
- package/src/ui/PullRequestList.tsx +128 -0
- package/src/ui/colors.ts +28 -0
- package/src/ui/diff.ts +220 -0
- package/src/ui/modals.tsx +294 -0
- package/src/ui/primitives.tsx +111 -0
- package/src/ui/pullRequests.ts +72 -0
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import type { PullRequestItem, PullRequestLabel } from "../domain.js"
|
|
2
|
+
import { colors } from "./colors.js"
|
|
3
|
+
|
|
4
|
+
export const shortRepoName = (repository: string) => repository.split("/")[1] ?? repository
|
|
5
|
+
|
|
6
|
+
export const repoColor = (repository: string) => colors.repos[shortRepoName(repository) as keyof typeof colors.repos] ?? colors.repos.default
|
|
7
|
+
|
|
8
|
+
export const reviewLabel = (pullRequest: PullRequestItem) => {
|
|
9
|
+
if (pullRequest.reviewStatus === "draft") return "draft"
|
|
10
|
+
if (pullRequest.reviewStatus === "approved") return "approved"
|
|
11
|
+
if (pullRequest.reviewStatus === "changes") return "changes"
|
|
12
|
+
if (pullRequest.reviewStatus === "review") return "review"
|
|
13
|
+
return null
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export const checkLabel = (pullRequest: PullRequestItem) => pullRequest.checkSummary
|
|
17
|
+
|
|
18
|
+
export const statusColor = (status: PullRequestItem["reviewStatus"] | PullRequestItem["checkStatus"]) => colors.status[status]
|
|
19
|
+
|
|
20
|
+
export const reviewIcon = (pullRequest: PullRequestItem) => {
|
|
21
|
+
if (pullRequest.autoMergeEnabled) return "↻"
|
|
22
|
+
if (pullRequest.reviewStatus === "draft") return "◌"
|
|
23
|
+
if (pullRequest.reviewStatus === "approved") return "✓"
|
|
24
|
+
if (pullRequest.reviewStatus === "changes") return "!"
|
|
25
|
+
if (pullRequest.reviewStatus === "review") return "◐"
|
|
26
|
+
return "·"
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const fallbackLabelColor = (name: string) => {
|
|
30
|
+
let hash = 0
|
|
31
|
+
for (const char of name) {
|
|
32
|
+
hash = (hash * 31 + char.charCodeAt(0)) >>> 0
|
|
33
|
+
}
|
|
34
|
+
const hue = hash % 360
|
|
35
|
+
return `hsl(${hue} 55% 35%)`
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export const labelColor = (label: PullRequestLabel) => label.color ?? fallbackLabelColor(label.name)
|
|
39
|
+
|
|
40
|
+
export const labelTextColor = (color: string) => {
|
|
41
|
+
if (color.startsWith("#") && color.length === 7) {
|
|
42
|
+
const red = Number.parseInt(color.slice(1, 3), 16)
|
|
43
|
+
const green = Number.parseInt(color.slice(3, 5), 16)
|
|
44
|
+
const blue = Number.parseInt(color.slice(5, 7), 16)
|
|
45
|
+
const luminance = (0.2126 * red + 0.7152 * green + 0.0722 * blue) / 255
|
|
46
|
+
return luminance > 0.6 ? "#111111" : "#f8fafc"
|
|
47
|
+
}
|
|
48
|
+
return "#f8fafc"
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export const groupBy = <T,>(items: readonly T[], getKey: (item: T) => string, orderedKeys: readonly string[] = []) => {
|
|
52
|
+
const groups = new Map<string, T[]>()
|
|
53
|
+
for (const item of items) {
|
|
54
|
+
const key = getKey(item)
|
|
55
|
+
const existing = groups.get(key)
|
|
56
|
+
if (existing) {
|
|
57
|
+
existing.push(item)
|
|
58
|
+
} else {
|
|
59
|
+
groups.set(key, [item])
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const order = new Map(orderedKeys.map((key, index) => [key, index]))
|
|
64
|
+
return [...groups.entries()].sort((left, right) => {
|
|
65
|
+
const leftIndex = order.get(left[0])
|
|
66
|
+
const rightIndex = order.get(right[0])
|
|
67
|
+
if (leftIndex !== undefined && rightIndex !== undefined) return leftIndex - rightIndex
|
|
68
|
+
if (leftIndex !== undefined) return -1
|
|
69
|
+
if (rightIndex !== undefined) return 1
|
|
70
|
+
return left[0].localeCompare(right[0])
|
|
71
|
+
})
|
|
72
|
+
}
|