opencode-github-pr 0.0.0-stage → 0.1.0
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/LICENSE +21 -0
- package/README.md +331 -2
- package/demo/demo.gif +0 -0
- package/demo/fixtures.ts +158 -0
- package/package.json +56 -4
- package/plugins/app/DashboardView.tsx +290 -0
- package/plugins/app/PRRow.tsx +209 -0
- package/plugins/app/actions.tsx +25 -0
- package/plugins/app/config.ts +85 -0
- package/plugins/app/theme.ts +62 -0
- package/plugins/app/usePRData.ts +193 -0
- package/plugins/domain/format.ts +38 -0
- package/plugins/domain/login.ts +33 -0
- package/plugins/domain/messages.ts +161 -0
- package/plugins/domain/pr-filters.ts +40 -0
- package/plugins/domain/pr-links.ts +12 -0
- package/plugins/domain/pr-status.ts +127 -0
- package/plugins/domain/types.ts +77 -0
- package/plugins/infra/git.ts +156 -0
- package/plugins/infra/github-enterprise.ts +31 -0
- package/plugins/infra/loader.ts +123 -0
- package/plugins/infra/mappers.ts +117 -0
- package/plugins/infra/octokit.ts +115 -0
- package/plugins/infra/queries.ts +69 -0
- package/plugins/pr-dashboard.ts +8 -0
- package/plugins/pr-dashboard.tui.tsx +154 -0
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
/** @jsxImportSource @opentui/solid */
|
|
2
|
+
import { createSignal, For, onCleanup, onMount, Show } from "solid-js"
|
|
3
|
+
import type { ResolvedTheme } from "@opencode/theme/tui"
|
|
4
|
+
import type { BoxRenderable } from "@opentui/core"
|
|
5
|
+
import { useRenderer } from "@opentui/solid"
|
|
6
|
+
import {
|
|
7
|
+
DashboardStatus,
|
|
8
|
+
type DashboardState,
|
|
9
|
+
type PRLinkTarget,
|
|
10
|
+
type PRListErrorKind,
|
|
11
|
+
type PRScope,
|
|
12
|
+
type PRStatusFilter,
|
|
13
|
+
} from "../domain/types"
|
|
14
|
+
import { filterPRs } from "../domain/pr-filters"
|
|
15
|
+
import { skin, type Skin } from "./theme"
|
|
16
|
+
import { errorMessages } from "../domain/messages"
|
|
17
|
+
import { PRRow } from "./PRRow"
|
|
18
|
+
import type { DashboardIcons } from "./config"
|
|
19
|
+
|
|
20
|
+
// GitHub returns up to 100 PRs per GraphQL page (see PULL_REQUESTS_QUERY).
|
|
21
|
+
const PRS_PER_PAGE = 100
|
|
22
|
+
|
|
23
|
+
export function DashboardView(props: {
|
|
24
|
+
theme: ResolvedTheme
|
|
25
|
+
state: DashboardState
|
|
26
|
+
setSelectedIdx: (n: number) => void
|
|
27
|
+
onOpen: (n: number, target?: PRLinkTarget) => void
|
|
28
|
+
scope: PRScope
|
|
29
|
+
statusFilter: PRStatusFilter
|
|
30
|
+
onCycleScope: () => void
|
|
31
|
+
onCycleStatus: () => void
|
|
32
|
+
pageSize: number
|
|
33
|
+
maxPRPages: number
|
|
34
|
+
colors: Partial<Skin>
|
|
35
|
+
icons: DashboardIcons
|
|
36
|
+
}) {
|
|
37
|
+
const sk = skin(props.theme, props.colors)
|
|
38
|
+
const [scopeHovered, setScopeHovered] = createSignal(false)
|
|
39
|
+
const [statusHovered, setStatusHovered] = createSignal(false)
|
|
40
|
+
const [page, setPage] = createSignal(0)
|
|
41
|
+
const [previousHovered, setPreviousHovered] = createSignal(false)
|
|
42
|
+
const [nextHovered, setNextHovered] = createSignal(false)
|
|
43
|
+
let view: BoxRenderable | undefined
|
|
44
|
+
const [titleWidth, setTitleWidth] = createSignal(48)
|
|
45
|
+
const renderer = useRenderer()
|
|
46
|
+
onMount(() => {
|
|
47
|
+
const updateTitleWidth = () => {
|
|
48
|
+
if (!view) return
|
|
49
|
+
const nextWidth = Math.max(1, Math.floor(view.width) - 2)
|
|
50
|
+
setTitleWidth((current) => current === nextWidth ? current : nextWidth)
|
|
51
|
+
}
|
|
52
|
+
renderer.on("frame", updateTitleWidth)
|
|
53
|
+
renderer.on("resize", updateTitleWidth)
|
|
54
|
+
onCleanup(() => {
|
|
55
|
+
renderer.off("frame", updateTitleWidth)
|
|
56
|
+
renderer.off("resize", updateTitleWidth)
|
|
57
|
+
})
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
const prs = () => filterPRs(
|
|
61
|
+
props.state.prs,
|
|
62
|
+
props.scope,
|
|
63
|
+
props.statusFilter,
|
|
64
|
+
props.state.currentBranch,
|
|
65
|
+
props.state.viewerLogin,
|
|
66
|
+
)
|
|
67
|
+
const pageCount = () => Math.max(1, Math.ceil(prs().length / props.pageSize))
|
|
68
|
+
const currentPage = () => Math.min(page(), pageCount() - 1)
|
|
69
|
+
const pagePRs = () =>
|
|
70
|
+
prs().slice(currentPage() * props.pageSize, (currentPage() + 1) * props.pageSize)
|
|
71
|
+
const canGoPrevious = () => currentPage() > 0
|
|
72
|
+
const canGoNext = () => currentPage() < pageCount() - 1
|
|
73
|
+
const listIsAvailable = () =>
|
|
74
|
+
props.state.status === DashboardStatus.Ok ||
|
|
75
|
+
(props.state.status === DashboardStatus.Error && props.state.prs.length > 0)
|
|
76
|
+
// Closed PRs load the first time a status filter shows them.
|
|
77
|
+
const closedPending = () =>
|
|
78
|
+
props.statusFilter !== "open" && !props.state.closedLoaded && props.state.status === DashboardStatus.Ok
|
|
79
|
+
const truncationNotice = () => {
|
|
80
|
+
const open = props.statusFilter !== "closed" && props.state.truncated.open
|
|
81
|
+
const closed = props.statusFilter !== "open" && props.state.truncated.closed
|
|
82
|
+
if (!open && !closed) return null
|
|
83
|
+
const which = open && closed ? "open and closed" : open ? "open" : "closed"
|
|
84
|
+
return `Showing ${props.maxPRPages * PRS_PER_PAGE} newest ${which} PRs`
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const errorPresentation = (): { title: string; description: string } => {
|
|
88
|
+
const detail = props.state.error ?? errorMessages.unknown
|
|
89
|
+
const kind: PRListErrorKind = props.state.errorKind ?? "unknown"
|
|
90
|
+
switch (kind) {
|
|
91
|
+
case "authentication":
|
|
92
|
+
return {
|
|
93
|
+
title: "GitHub sign-in failed",
|
|
94
|
+
description: "Set GITHUB_TOKEN or GH_TOKEN.",
|
|
95
|
+
}
|
|
96
|
+
case "forbidden":
|
|
97
|
+
return {
|
|
98
|
+
title: "Permission denied",
|
|
99
|
+
description: "Give your token read access to this repo.",
|
|
100
|
+
}
|
|
101
|
+
case "rate-limit":
|
|
102
|
+
const retryAt = /(?:resets at|try again at)\s+(.+?)(?:\.)?$/i.exec(detail)?.[1]
|
|
103
|
+
return {
|
|
104
|
+
title: "Rate limit exceeded",
|
|
105
|
+
description: retryAt ? `Try again at ${retryAt.replace(/\.$/, "")}.` : "Wait a little, then try again.",
|
|
106
|
+
}
|
|
107
|
+
case "not-found":
|
|
108
|
+
return {
|
|
109
|
+
title: "Repo not found",
|
|
110
|
+
description: "Check the URL and your access.",
|
|
111
|
+
}
|
|
112
|
+
case "invalid-query":
|
|
113
|
+
return {
|
|
114
|
+
title: "Invalid request",
|
|
115
|
+
description: "Update the plugin, then refresh.",
|
|
116
|
+
}
|
|
117
|
+
case "timeout":
|
|
118
|
+
return {
|
|
119
|
+
title: "Request timed out",
|
|
120
|
+
description: "Try again. Check your connection if it keeps happening.",
|
|
121
|
+
}
|
|
122
|
+
case "network":
|
|
123
|
+
return {
|
|
124
|
+
title: "Cannot reach GitHub",
|
|
125
|
+
description: "Check your internet connection and try again.",
|
|
126
|
+
}
|
|
127
|
+
case "server":
|
|
128
|
+
return {
|
|
129
|
+
title: "GitHub is unavailable",
|
|
130
|
+
description: "Try again in a moment.",
|
|
131
|
+
}
|
|
132
|
+
case "unknown":
|
|
133
|
+
return {
|
|
134
|
+
title: "Couldn't load PRs",
|
|
135
|
+
description: `Try again. Details: ${detail}`,
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
return (
|
|
141
|
+
<box
|
|
142
|
+
ref={(element) => { view = element }}
|
|
143
|
+
flexDirection="column"
|
|
144
|
+
paddingTop={1}
|
|
145
|
+
paddingBottom={1}
|
|
146
|
+
gap={0}
|
|
147
|
+
width="100%"
|
|
148
|
+
backgroundColor={sk.panel}
|
|
149
|
+
>
|
|
150
|
+
<box
|
|
151
|
+
flexDirection="row"
|
|
152
|
+
gap={1}
|
|
153
|
+
paddingLeft={0}
|
|
154
|
+
paddingRight={0}
|
|
155
|
+
>
|
|
156
|
+
<text fg={sk.text}>
|
|
157
|
+
<b>Pull Requests</b>
|
|
158
|
+
</text>
|
|
159
|
+
<box flexGrow={1}></box>
|
|
160
|
+
<box flexDirection="row" gap={2}>
|
|
161
|
+
<text
|
|
162
|
+
fg={scopeHovered() ? sk.accent : sk.muted}
|
|
163
|
+
selectable={false}
|
|
164
|
+
onMouseOver={() => setScopeHovered(true)}
|
|
165
|
+
onMouseOut={() => setScopeHovered(false)}
|
|
166
|
+
onMouseUp={() => props.onCycleScope()}
|
|
167
|
+
>
|
|
168
|
+
{`${props.icons.scope} ${props.scope}`}
|
|
169
|
+
</text>
|
|
170
|
+
<text
|
|
171
|
+
fg={statusHovered() ? sk.accent : sk.muted}
|
|
172
|
+
selectable={false}
|
|
173
|
+
onMouseOver={() => setStatusHovered(true)}
|
|
174
|
+
onMouseOut={() => setStatusHovered(false)}
|
|
175
|
+
onMouseUp={() => props.onCycleStatus()}
|
|
176
|
+
>
|
|
177
|
+
{`${props.icons.status} ${props.statusFilter}`}
|
|
178
|
+
</text>
|
|
179
|
+
</box>
|
|
180
|
+
</box>
|
|
181
|
+
|
|
182
|
+
<Show when={props.state.status === DashboardStatus.Loading}>
|
|
183
|
+
<box flexDirection="column" paddingLeft={1} paddingTop={1} paddingRight={1}>
|
|
184
|
+
<text fg={sk.muted} selectable={false}>{props.icons.loading} Loading PRs</text>
|
|
185
|
+
<text fg={sk.muted} selectable={false}> Checking GitHub…</text>
|
|
186
|
+
</box>
|
|
187
|
+
</Show>
|
|
188
|
+
|
|
189
|
+
<Show when={closedPending()}>
|
|
190
|
+
<box flexDirection="column" paddingLeft={1} paddingTop={1} paddingRight={1}>
|
|
191
|
+
<text fg={sk.muted} selectable={false}>{props.icons.loading} Loading closed PRs</text>
|
|
192
|
+
</box>
|
|
193
|
+
</Show>
|
|
194
|
+
|
|
195
|
+
<Show when={truncationNotice()}>
|
|
196
|
+
<box flexDirection="column" paddingLeft={1}>
|
|
197
|
+
<text fg={sk.warning} selectable={false}>{truncationNotice()}</text>
|
|
198
|
+
<text fg={sk.muted} selectable={false}> More exist; raise maxPRPages to load them.</text>
|
|
199
|
+
</box>
|
|
200
|
+
</Show>
|
|
201
|
+
|
|
202
|
+
<Show when={props.state.status === DashboardStatus.NoRepo}>
|
|
203
|
+
<box flexDirection="column" paddingLeft={1} paddingTop={1} paddingRight={1}>
|
|
204
|
+
<text fg={sk.muted} selectable={false}>{props.icons.info} No GitHub repo</text>
|
|
205
|
+
<text fg={sk.muted} selectable={false}> Add a GitHub remote or switch to the right project.</text>
|
|
206
|
+
</box>
|
|
207
|
+
</Show>
|
|
208
|
+
|
|
209
|
+
<Show when={props.state.status === DashboardStatus.Error}>
|
|
210
|
+
<box flexDirection="column" paddingLeft={1} paddingTop={1} paddingRight={1}>
|
|
211
|
+
<text fg={sk.error} selectable={false}>{props.icons.error} {errorPresentation().title}</text>
|
|
212
|
+
<text fg={sk.muted} selectable={false}> {errorPresentation().description}</text>
|
|
213
|
+
</box>
|
|
214
|
+
</Show>
|
|
215
|
+
|
|
216
|
+
<Show
|
|
217
|
+
when={
|
|
218
|
+
listIsAvailable() &&
|
|
219
|
+
!closedPending() &&
|
|
220
|
+
prs().length === 0 &&
|
|
221
|
+
(props.state.status === DashboardStatus.Ok || props.state.prs.length > 0)
|
|
222
|
+
}
|
|
223
|
+
>
|
|
224
|
+
<box flexDirection="column" paddingLeft={1} paddingTop={1} paddingRight={1}>
|
|
225
|
+
<text fg={sk.muted} selectable={false}>{props.icons.info} {errorMessages.noMatchingPRs}</text>
|
|
226
|
+
<text fg={sk.muted} selectable={false}> Try a different scope or status.</text>
|
|
227
|
+
</box>
|
|
228
|
+
</Show>
|
|
229
|
+
|
|
230
|
+
<Show when={listIsAvailable() && prs().length > 0}>
|
|
231
|
+
<box flexDirection="column" gap={0} width="100%">
|
|
232
|
+
<box flexDirection="column" gap={1} paddingTop={1} width="100%">
|
|
233
|
+
<For each={pagePRs()}>
|
|
234
|
+
{(pr, i) => (
|
|
235
|
+
<PRRow
|
|
236
|
+
pr={pr}
|
|
237
|
+
titleWidth={titleWidth()}
|
|
238
|
+
secondaryBackground={sk.panelAlt}
|
|
239
|
+
onClick={(target) => {
|
|
240
|
+
props.setSelectedIdx(currentPage() * props.pageSize + i())
|
|
241
|
+
props.onOpen(pr.number, target)
|
|
242
|
+
}}
|
|
243
|
+
text={sk.text}
|
|
244
|
+
muted={sk.muted}
|
|
245
|
+
pass={sk.success}
|
|
246
|
+
fail={sk.error}
|
|
247
|
+
warn={sk.warning}
|
|
248
|
+
draft={sk.draft}
|
|
249
|
+
merged={sk.merged}
|
|
250
|
+
icons={props.icons}
|
|
251
|
+
/>
|
|
252
|
+
)}
|
|
253
|
+
</For>
|
|
254
|
+
</box>
|
|
255
|
+
<Show when={pageCount() > 1}>
|
|
256
|
+
<box
|
|
257
|
+
flexDirection="row"
|
|
258
|
+
justifyContent="flex-end"
|
|
259
|
+
gap={1}
|
|
260
|
+
paddingTop={1}
|
|
261
|
+
width="100%"
|
|
262
|
+
border={["top"]}
|
|
263
|
+
borderColor={previousHovered() || nextHovered() ? sk.borderActive : sk.border}
|
|
264
|
+
>
|
|
265
|
+
<text
|
|
266
|
+
fg={canGoPrevious() && previousHovered() ? sk.accent : sk.muted}
|
|
267
|
+
selectable={false}
|
|
268
|
+
onMouseOver={() => canGoPrevious() && setPreviousHovered(true)}
|
|
269
|
+
onMouseOut={() => setPreviousHovered(false)}
|
|
270
|
+
onMouseUp={() => canGoPrevious() && setPage(currentPage() - 1)}
|
|
271
|
+
>
|
|
272
|
+
{props.icons.previousPage}
|
|
273
|
+
</text>
|
|
274
|
+
<text fg={sk.muted} selectable={false}>{`${currentPage() + 1} of ${pageCount()}`}</text>
|
|
275
|
+
<text
|
|
276
|
+
fg={canGoNext() && nextHovered() ? sk.accent : sk.muted}
|
|
277
|
+
selectable={false}
|
|
278
|
+
onMouseOver={() => canGoNext() && setNextHovered(true)}
|
|
279
|
+
onMouseOut={() => setNextHovered(false)}
|
|
280
|
+
onMouseUp={() => canGoNext() && setPage(currentPage() + 1)}
|
|
281
|
+
>
|
|
282
|
+
{props.icons.nextPage}
|
|
283
|
+
</text>
|
|
284
|
+
</box>
|
|
285
|
+
</Show>
|
|
286
|
+
</box>
|
|
287
|
+
</Show>
|
|
288
|
+
</box>
|
|
289
|
+
)
|
|
290
|
+
}
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
/** @jsxImportSource @opentui/solid */
|
|
2
|
+
import { createSignal, For, Show } from "solid-js"
|
|
3
|
+
import type { PR, PRLinkTarget } from "../domain/types"
|
|
4
|
+
import { truncateTitle } from "../domain/format"
|
|
5
|
+
import {
|
|
6
|
+
checkStatusGroups,
|
|
7
|
+
commentThreadCounts,
|
|
8
|
+
reviewStatusGroups,
|
|
9
|
+
type StatusCategory,
|
|
10
|
+
} from "../domain/pr-status"
|
|
11
|
+
|
|
12
|
+
function statusColor(status: StatusCategory, props: {
|
|
13
|
+
pass: string
|
|
14
|
+
fail: string
|
|
15
|
+
warn: string
|
|
16
|
+
muted: string
|
|
17
|
+
}): string {
|
|
18
|
+
return {
|
|
19
|
+
pass: props.pass,
|
|
20
|
+
fail: props.fail,
|
|
21
|
+
pending: props.warn,
|
|
22
|
+
neutral: props.muted,
|
|
23
|
+
none: props.muted,
|
|
24
|
+
}[status]
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function ClickableText(props: {
|
|
28
|
+
label: string
|
|
29
|
+
color: string
|
|
30
|
+
target: PRLinkTarget
|
|
31
|
+
onClick: (target: PRLinkTarget) => void
|
|
32
|
+
}) {
|
|
33
|
+
const [hovered, setHovered] = createSignal(false)
|
|
34
|
+
return (
|
|
35
|
+
<text
|
|
36
|
+
fg={props.color}
|
|
37
|
+
selectable={false}
|
|
38
|
+
onMouseOver={(event) => {
|
|
39
|
+
event.stopPropagation()
|
|
40
|
+
setHovered(true)
|
|
41
|
+
}}
|
|
42
|
+
onMouseOut={(event) => {
|
|
43
|
+
event.stopPropagation()
|
|
44
|
+
setHovered(false)
|
|
45
|
+
}}
|
|
46
|
+
onMouseUp={(event) => {
|
|
47
|
+
event.stopPropagation()
|
|
48
|
+
props.onClick(props.target)
|
|
49
|
+
}}
|
|
50
|
+
>
|
|
51
|
+
{hovered() ? <u>{props.label}</u> : props.label}
|
|
52
|
+
</text>
|
|
53
|
+
)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function ClickableComment(props: {
|
|
57
|
+
icon: string
|
|
58
|
+
count: number
|
|
59
|
+
color: string
|
|
60
|
+
onClick: (target: PRLinkTarget) => void
|
|
61
|
+
}) {
|
|
62
|
+
const [hovered, setHovered] = createSignal(false)
|
|
63
|
+
return (
|
|
64
|
+
<box
|
|
65
|
+
flexDirection="row"
|
|
66
|
+
gap={1}
|
|
67
|
+
onMouseOver={(event) => {
|
|
68
|
+
event.stopPropagation()
|
|
69
|
+
setHovered(true)
|
|
70
|
+
}}
|
|
71
|
+
onMouseOut={(event) => {
|
|
72
|
+
event.stopPropagation()
|
|
73
|
+
setHovered(false)
|
|
74
|
+
}}
|
|
75
|
+
onMouseUp={(event) => {
|
|
76
|
+
event.stopPropagation()
|
|
77
|
+
props.onClick("files")
|
|
78
|
+
}}
|
|
79
|
+
>
|
|
80
|
+
<text fg={props.color} selectable={false}>
|
|
81
|
+
{hovered() ? <u>{props.icon}</u> : props.icon}
|
|
82
|
+
</text>
|
|
83
|
+
<text fg={props.color} selectable={false}>
|
|
84
|
+
{hovered() ? <u>{props.count}</u> : props.count}
|
|
85
|
+
</text>
|
|
86
|
+
</box>
|
|
87
|
+
)
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export function PRRow(props: {
|
|
91
|
+
pr: PR
|
|
92
|
+
titleWidth: number
|
|
93
|
+
secondaryBackground: string
|
|
94
|
+
onClick: (target: PRLinkTarget) => void
|
|
95
|
+
text: string
|
|
96
|
+
muted: string
|
|
97
|
+
pass: string
|
|
98
|
+
fail: string
|
|
99
|
+
warn: string
|
|
100
|
+
draft: string
|
|
101
|
+
merged: string
|
|
102
|
+
icons: {
|
|
103
|
+
openPR: string
|
|
104
|
+
mergedPR: string
|
|
105
|
+
review: string
|
|
106
|
+
openComment: string
|
|
107
|
+
check: string
|
|
108
|
+
}
|
|
109
|
+
}) {
|
|
110
|
+
const [titleHovered, setTitleHovered] = createSignal(false)
|
|
111
|
+
const title = () => truncateTitle(props.pr.title, props.titleWidth)
|
|
112
|
+
const icon = props.pr.isMerged ? props.icons.mergedPR : props.icons.openPR
|
|
113
|
+
const iconColor = props.pr.isMerged
|
|
114
|
+
? props.merged
|
|
115
|
+
: props.pr.isDraft
|
|
116
|
+
? props.draft
|
|
117
|
+
: props.pr.mergeable === "MERGEABLE"
|
|
118
|
+
? props.pass
|
|
119
|
+
: props.pr.mergeable === "CONFLICTING"
|
|
120
|
+
? props.fail
|
|
121
|
+
: props.muted
|
|
122
|
+
const checks = checkStatusGroups(props.pr)
|
|
123
|
+
const reviews = reviewStatusGroups(props.pr)
|
|
124
|
+
const comments = commentThreadCounts(props.pr)
|
|
125
|
+
const commentStatuses = comments?.open
|
|
126
|
+
? [{ icon: props.icons.openComment, count: comments.open }]
|
|
127
|
+
: []
|
|
128
|
+
|
|
129
|
+
return (
|
|
130
|
+
<box
|
|
131
|
+
flexDirection="column"
|
|
132
|
+
width="100%"
|
|
133
|
+
paddingLeft={0}
|
|
134
|
+
paddingRight={0}
|
|
135
|
+
>
|
|
136
|
+
<box
|
|
137
|
+
flexDirection="row"
|
|
138
|
+
gap={1}
|
|
139
|
+
width="100%"
|
|
140
|
+
onMouseOver={() => setTitleHovered(true)}
|
|
141
|
+
onMouseOut={() => setTitleHovered(false)}
|
|
142
|
+
onMouseUp={() => props.onClick("overview")}
|
|
143
|
+
>
|
|
144
|
+
<ClickableText
|
|
145
|
+
label={icon}
|
|
146
|
+
color={iconColor}
|
|
147
|
+
target="mergeStatus"
|
|
148
|
+
onClick={props.onClick}
|
|
149
|
+
/>
|
|
150
|
+
<text fg={props.text} selectable={false} height={1} wrapMode="none">
|
|
151
|
+
{titleHovered() ? <u>{title()}</u> : title()}
|
|
152
|
+
</text>
|
|
153
|
+
</box>
|
|
154
|
+
<box flexDirection="row" gap={1} paddingLeft={2} width="100%" backgroundColor={props.secondaryBackground}>
|
|
155
|
+
<ClickableText
|
|
156
|
+
label={`#${props.pr.number}`}
|
|
157
|
+
color={props.muted}
|
|
158
|
+
target="overview"
|
|
159
|
+
onClick={props.onClick}
|
|
160
|
+
/>
|
|
161
|
+
<ClickableText
|
|
162
|
+
label={`+${props.pr.additions}`}
|
|
163
|
+
color={props.pass}
|
|
164
|
+
target="files"
|
|
165
|
+
onClick={props.onClick}
|
|
166
|
+
/>
|
|
167
|
+
<ClickableText
|
|
168
|
+
label={`-${props.pr.deletions}`}
|
|
169
|
+
color={props.fail}
|
|
170
|
+
target="files"
|
|
171
|
+
onClick={props.onClick}
|
|
172
|
+
/>
|
|
173
|
+
<box flexGrow={1}></box>
|
|
174
|
+
<Show when={commentStatuses.length > 0}>
|
|
175
|
+
<For each={commentStatuses}>
|
|
176
|
+
{(comment) => (
|
|
177
|
+
<ClickableComment
|
|
178
|
+
icon={comment.icon}
|
|
179
|
+
count={comment.count}
|
|
180
|
+
color={props.muted}
|
|
181
|
+
onClick={props.onClick}
|
|
182
|
+
/>
|
|
183
|
+
)}
|
|
184
|
+
</For>
|
|
185
|
+
</Show>
|
|
186
|
+
<For each={reviews}>
|
|
187
|
+
{(group) => (
|
|
188
|
+
<ClickableText
|
|
189
|
+
label={`${props.icons.review}${reviews.length > 1 ? group.count : ""}`}
|
|
190
|
+
color={statusColor(group.status, props)}
|
|
191
|
+
target="overview"
|
|
192
|
+
onClick={props.onClick}
|
|
193
|
+
/>
|
|
194
|
+
)}
|
|
195
|
+
</For>
|
|
196
|
+
<For each={checks}>
|
|
197
|
+
{(group) => (
|
|
198
|
+
<ClickableText
|
|
199
|
+
label={`${props.icons.check}${checks.length > 1 ? group.count : ""}`}
|
|
200
|
+
color={statusColor(group.status, props)}
|
|
201
|
+
target="checks"
|
|
202
|
+
onClick={props.onClick}
|
|
203
|
+
/>
|
|
204
|
+
)}
|
|
205
|
+
</For>
|
|
206
|
+
</box>
|
|
207
|
+
</box>
|
|
208
|
+
)
|
|
209
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/** @jsxImportSource @opentui/solid */
|
|
2
|
+
import open from "open"
|
|
3
|
+
import type { Context as TuiPluginContext } from "@opencode/plugin/tui/context"
|
|
4
|
+
import { prTargetUrl } from "../domain/pr-links"
|
|
5
|
+
import type { DashboardContext, PRLinkTarget } from "../domain/types"
|
|
6
|
+
|
|
7
|
+
export interface PrActions {
|
|
8
|
+
openPR: (n: number, target?: PRLinkTarget) => Promise<void>
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
// Build callbacks used by the sidebar and keymap using the V2 local TUI API.
|
|
12
|
+
export function createActions(api: TuiPluginContext, ctx: DashboardContext): PrActions {
|
|
13
|
+
const openPR = async (n: number, target: PRLinkTarget = "overview") => {
|
|
14
|
+
const pr = ctx.state().prs.find((p) => p.number === n)
|
|
15
|
+
if (!pr) return
|
|
16
|
+
try {
|
|
17
|
+
await open(prTargetUrl(pr.url, target))
|
|
18
|
+
api.ui.toast.show({ variant: "info", message: `Opening #${n} in browser…`, duration: 1500 })
|
|
19
|
+
} catch {
|
|
20
|
+
api.ui.toast.show({ variant: "error", message: `Couldn't open #${n} in browser`, duration: 2500 })
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return { openPR }
|
|
25
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import type { PRScope, PRStatusFilter } from "../domain/types"
|
|
2
|
+
import { DEFAULT_SKIN, type Skin } from "./theme"
|
|
3
|
+
|
|
4
|
+
export const DEFAULT_ICONS = {
|
|
5
|
+
openPR: "",
|
|
6
|
+
mergedPR: "",
|
|
7
|
+
review: "",
|
|
8
|
+
openComment: "",
|
|
9
|
+
check: "●",
|
|
10
|
+
scope: "",
|
|
11
|
+
status: "",
|
|
12
|
+
loading: "",
|
|
13
|
+
info: "",
|
|
14
|
+
error: "",
|
|
15
|
+
previousPage: "",
|
|
16
|
+
nextPage: "",
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export type DashboardIcons = Record<keyof typeof DEFAULT_ICONS, string>
|
|
20
|
+
|
|
21
|
+
export type DashboardOptions = {
|
|
22
|
+
enabled: boolean
|
|
23
|
+
pageSize: number
|
|
24
|
+
maxPRPages: number
|
|
25
|
+
refreshIntervalMs: number
|
|
26
|
+
requestTimeoutMs: number
|
|
27
|
+
defaultScope: PRScope
|
|
28
|
+
defaultStatusFilter: PRStatusFilter
|
|
29
|
+
colors: Partial<Skin>
|
|
30
|
+
icons: DashboardIcons
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
type DashboardOptionsInput = {
|
|
34
|
+
enabled?: unknown
|
|
35
|
+
pageSize?: unknown
|
|
36
|
+
maxPRPages?: unknown
|
|
37
|
+
refreshIntervalMs?: unknown
|
|
38
|
+
requestTimeoutMs?: unknown
|
|
39
|
+
defaultScope?: unknown
|
|
40
|
+
defaultStatusFilter?: unknown
|
|
41
|
+
colors?: unknown
|
|
42
|
+
icons?: unknown
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const scopes: PRScope[] = ["branch", "author", "assignee", "all"]
|
|
46
|
+
const statusFilters: PRStatusFilter[] = ["open", "closed", "all"]
|
|
47
|
+
|
|
48
|
+
export const DEFAULT_PAGE_SIZE = 5
|
|
49
|
+
export const DEFAULT_MAX_PR_PAGES = 1
|
|
50
|
+
export const DEFAULT_REFRESH_INTERVAL_MS = 60_000
|
|
51
|
+
export const DEFAULT_REQUEST_TIMEOUT_MS = 15_000
|
|
52
|
+
|
|
53
|
+
function positiveNumber(value: unknown, fallback: number): number {
|
|
54
|
+
return typeof value === "number" && Number.isFinite(value) && value > 0 ? Math.max(1, Math.floor(value)) : fallback
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function stringOverrides<T extends Record<string, string>>(defaults: T, input: unknown): Partial<T> {
|
|
58
|
+
if (!input || typeof input !== "object" || Array.isArray(input)) return {}
|
|
59
|
+
const result: Partial<T> = {}
|
|
60
|
+
for (const key of Object.keys(defaults) as Array<keyof T>) {
|
|
61
|
+
const value = (input as Record<string, unknown>)[key as string]
|
|
62
|
+
if (typeof value === "string" && value.trim()) result[key] = value as T[keyof T]
|
|
63
|
+
}
|
|
64
|
+
return result
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function mergeStrings<T extends Record<string, string>>(defaults: T, input: unknown): T {
|
|
68
|
+
return { ...defaults, ...stringOverrides(defaults, input) }
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export function dashboardOptions(input: DashboardOptionsInput = {}): DashboardOptions {
|
|
72
|
+
return {
|
|
73
|
+
enabled: input.enabled !== false,
|
|
74
|
+
pageSize: positiveNumber(input.pageSize, DEFAULT_PAGE_SIZE),
|
|
75
|
+
maxPRPages: positiveNumber(input.maxPRPages, DEFAULT_MAX_PR_PAGES),
|
|
76
|
+
refreshIntervalMs: positiveNumber(input.refreshIntervalMs, DEFAULT_REFRESH_INTERVAL_MS),
|
|
77
|
+
requestTimeoutMs: positiveNumber(input.requestTimeoutMs, DEFAULT_REQUEST_TIMEOUT_MS),
|
|
78
|
+
defaultScope: scopes.includes(input.defaultScope as PRScope) ? (input.defaultScope as PRScope) : "author",
|
|
79
|
+
defaultStatusFilter: statusFilters.includes(input.defaultStatusFilter as PRStatusFilter)
|
|
80
|
+
? (input.defaultStatusFilter as PRStatusFilter)
|
|
81
|
+
: "open",
|
|
82
|
+
colors: stringOverrides(DEFAULT_SKIN, input.colors),
|
|
83
|
+
icons: mergeStrings(DEFAULT_ICONS, input.icons),
|
|
84
|
+
}
|
|
85
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
// Convert OpenCode V2 semantic theme tokens into the palette used by the PR
|
|
2
|
+
// dashboard components.
|
|
3
|
+
|
|
4
|
+
import type { ResolvedTheme } from "@opencode/theme/tui"
|
|
5
|
+
|
|
6
|
+
export const DEFAULT_SKIN = {
|
|
7
|
+
panel: "#161616",
|
|
8
|
+
panelAlt: "#1d1d1d",
|
|
9
|
+
border: "#3a3a3a",
|
|
10
|
+
borderActive: "#5f87ff",
|
|
11
|
+
text: "#e5e5e5",
|
|
12
|
+
muted: "#888888",
|
|
13
|
+
accent: "#5f87ff",
|
|
14
|
+
success: "#5fbf5f",
|
|
15
|
+
warning: "#d8a657",
|
|
16
|
+
error: "#d86565",
|
|
17
|
+
draft: "#888888",
|
|
18
|
+
merged: "#a371f7",
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export type Skin = {
|
|
22
|
+
panel: string
|
|
23
|
+
panelAlt: string
|
|
24
|
+
border: string
|
|
25
|
+
borderActive: string
|
|
26
|
+
text: string
|
|
27
|
+
muted: string
|
|
28
|
+
accent: string
|
|
29
|
+
success: string
|
|
30
|
+
warning: string
|
|
31
|
+
error: string
|
|
32
|
+
draft: string
|
|
33
|
+
merged: string
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function toHex(c: { toInts(): [number, number, number, number] }): string {
|
|
37
|
+
const [r, g, b] = c.toInts()
|
|
38
|
+
return (
|
|
39
|
+
"#" +
|
|
40
|
+
[r, g, b]
|
|
41
|
+
.map((n) => Math.max(0, Math.min(255, n)).toString(16).padStart(2, "0"))
|
|
42
|
+
.join("")
|
|
43
|
+
)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function skin(t: ResolvedTheme, overrides: Partial<Skin> = {}): Skin {
|
|
47
|
+
return {
|
|
48
|
+
panel: toHex(t.background.base),
|
|
49
|
+
panelAlt: toHex(t.background.raised.base),
|
|
50
|
+
border: toHex(t.border.base),
|
|
51
|
+
borderActive: toHex(t.text.action.primary.base),
|
|
52
|
+
text: toHex(t.text.base),
|
|
53
|
+
muted: toHex(t.text.muted),
|
|
54
|
+
accent: toHex(t.text.action.primary.base),
|
|
55
|
+
success: toHex(t.text.feedback.success.base),
|
|
56
|
+
warning: toHex(t.text.feedback.warning.base),
|
|
57
|
+
error: toHex(t.text.feedback.error.base),
|
|
58
|
+
draft: toHex(t.text.muted),
|
|
59
|
+
merged: toHex(t.text.action.primary.base),
|
|
60
|
+
...overrides,
|
|
61
|
+
}
|
|
62
|
+
}
|