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,154 @@
|
|
|
1
|
+
/** @jsxImportSource @opentui/solid */
|
|
2
|
+
import { createSignal } from "solid-js"
|
|
3
|
+
import { Plugin } from "@opencode/plugin/tui"
|
|
4
|
+
import type { Context as TuiPluginContext } from "@opencode/plugin/tui/context"
|
|
5
|
+
import {
|
|
6
|
+
DashboardStatus,
|
|
7
|
+
type DashboardContext,
|
|
8
|
+
type DashboardState,
|
|
9
|
+
type PRScope,
|
|
10
|
+
type PRStatusFilter,
|
|
11
|
+
} from "./domain/types"
|
|
12
|
+
import { filterPRs, nextPRScope, nextPRStatusFilter } from "./domain/pr-filters"
|
|
13
|
+
import { DashboardView } from "./app/DashboardView"
|
|
14
|
+
import { useDashboard } from "./app/usePRData"
|
|
15
|
+
import { createActions } from "./app/actions"
|
|
16
|
+
import { dashboardOptions } from "./app/config"
|
|
17
|
+
|
|
18
|
+
const command = {
|
|
19
|
+
refresh: "opencode-github-pr.refresh",
|
|
20
|
+
open: "opencode-github-pr.open",
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
async function setup(api: TuiPluginContext) {
|
|
24
|
+
const options = dashboardOptions(api.options)
|
|
25
|
+
if (!options.enabled) return
|
|
26
|
+
|
|
27
|
+
const [state, setState] = createSignal<DashboardState>({
|
|
28
|
+
status: DashboardStatus.Loading,
|
|
29
|
+
repo: null,
|
|
30
|
+
prs: [],
|
|
31
|
+
currentBranch: null,
|
|
32
|
+
viewerLogin: null,
|
|
33
|
+
fetchedAt: null,
|
|
34
|
+
closedLoaded: false,
|
|
35
|
+
truncated: { open: false, closed: false },
|
|
36
|
+
})
|
|
37
|
+
const demoMode = process.env.OPENCODE_GITHUB_PR_DEMO === "1"
|
|
38
|
+
if (demoMode) {
|
|
39
|
+
const { demoDashboardState } = await import("../demo/fixtures")
|
|
40
|
+
setState(demoDashboardState())
|
|
41
|
+
}
|
|
42
|
+
const [selectedIdx, setSelectedIdx] = createSignal(0)
|
|
43
|
+
const [scope, setScope] = createSignal<PRScope>(options.defaultScope)
|
|
44
|
+
const [statusFilter, setStatusFilter] = createSignal<PRStatusFilter>(options.defaultStatusFilter)
|
|
45
|
+
const visiblePRs = () =>
|
|
46
|
+
filterPRs(state().prs, scope(), statusFilter(), state().currentBranch, state().viewerLogin)
|
|
47
|
+
const cycleScope = () => {
|
|
48
|
+
setScope(nextPRScope(scope()))
|
|
49
|
+
setSelectedIdx(0)
|
|
50
|
+
}
|
|
51
|
+
const cycleStatus = () => {
|
|
52
|
+
setStatusFilter(nextPRStatusFilter(statusFilter()))
|
|
53
|
+
setSelectedIdx(0)
|
|
54
|
+
// Closed PRs load on demand; fetch them (or refresh a cached copy).
|
|
55
|
+
if (statusFilter() !== "open") void dash.refresh()
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const dash = demoMode
|
|
59
|
+
? { refresh: async () => {}, refreshOne: async () => {} }
|
|
60
|
+
: useDashboard(
|
|
61
|
+
api,
|
|
62
|
+
state,
|
|
63
|
+
setState,
|
|
64
|
+
options.requestTimeoutMs,
|
|
65
|
+
options.maxPRPages,
|
|
66
|
+
() => statusFilter() !== "open",
|
|
67
|
+
)
|
|
68
|
+
const dashboard: DashboardContext = {
|
|
69
|
+
state,
|
|
70
|
+
refresh: dash.refresh,
|
|
71
|
+
refreshOne: dash.refreshOne,
|
|
72
|
+
selectedIdx,
|
|
73
|
+
setSelectedIdx,
|
|
74
|
+
}
|
|
75
|
+
const actions = createActions(api, dashboard)
|
|
76
|
+
|
|
77
|
+
if (!demoMode) void dash.refresh()
|
|
78
|
+
|
|
79
|
+
const unregisterSlot = api.ui.slot({
|
|
80
|
+
append: "sidebar.content",
|
|
81
|
+
render: () => (
|
|
82
|
+
<DashboardView
|
|
83
|
+
theme={api.theme}
|
|
84
|
+
state={state()}
|
|
85
|
+
setSelectedIdx={setSelectedIdx}
|
|
86
|
+
onOpen={actions.openPR}
|
|
87
|
+
scope={scope()}
|
|
88
|
+
statusFilter={statusFilter()}
|
|
89
|
+
onCycleScope={cycleScope}
|
|
90
|
+
onCycleStatus={cycleStatus}
|
|
91
|
+
pageSize={options.pageSize}
|
|
92
|
+
maxPRPages={options.maxPRPages}
|
|
93
|
+
colors={options.colors}
|
|
94
|
+
icons={options.icons}
|
|
95
|
+
/>
|
|
96
|
+
),
|
|
97
|
+
})
|
|
98
|
+
// OpenCode 2.0 provides Keymap.Provider through the TUI's Solid render
|
|
99
|
+
// context. Register this from a slot render rather than setup so the
|
|
100
|
+
// provider is present on early V2 host releases as well.
|
|
101
|
+
const unregisterKeymapSlot = api.ui.slot({
|
|
102
|
+
append: "app",
|
|
103
|
+
render: () => {
|
|
104
|
+
api.keymap.layer(() => ({
|
|
105
|
+
mode: "global",
|
|
106
|
+
commands: [
|
|
107
|
+
{
|
|
108
|
+
id: command.refresh,
|
|
109
|
+
title: "PRs: Refresh dashboard",
|
|
110
|
+
group: "PR Dashboard",
|
|
111
|
+
palette: true,
|
|
112
|
+
slash: { name: "pr-refresh" },
|
|
113
|
+
run() {
|
|
114
|
+
void dash.refresh()
|
|
115
|
+
api.ui.toast.show({ variant: "info", message: "Refreshing PRs…", duration: 1200 })
|
|
116
|
+
},
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
id: command.open,
|
|
120
|
+
title: "PRs: Open selected in browser",
|
|
121
|
+
group: "PR Dashboard",
|
|
122
|
+
palette: true,
|
|
123
|
+
slash: { name: "pr-open" },
|
|
124
|
+
enabled: () => visiblePRs().length > 0,
|
|
125
|
+
run() {
|
|
126
|
+
const pr = visiblePRs()[selectedIdx()]
|
|
127
|
+
if (pr) void actions.openPR(pr.number)
|
|
128
|
+
},
|
|
129
|
+
},
|
|
130
|
+
],
|
|
131
|
+
}))
|
|
132
|
+
return null
|
|
133
|
+
},
|
|
134
|
+
})
|
|
135
|
+
|
|
136
|
+
const stopOnIdle = api.data.on("session.idle", () => {
|
|
137
|
+
void dash.refresh()
|
|
138
|
+
})
|
|
139
|
+
const interval = setInterval(() => {
|
|
140
|
+
if (api.ui.router.current().type === "session") void dash.refresh()
|
|
141
|
+
}, options.refreshIntervalMs)
|
|
142
|
+
|
|
143
|
+
return () => {
|
|
144
|
+
clearInterval(interval)
|
|
145
|
+
stopOnIdle()
|
|
146
|
+
unregisterSlot()
|
|
147
|
+
unregisterKeymapSlot()
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
export default Plugin.define({
|
|
152
|
+
id: "opencode-github-pr.tui",
|
|
153
|
+
setup,
|
|
154
|
+
})
|