opencode-github-pr 0.0.0-stage → 0.2.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 +440 -2
- package/demo/fixtures.ts +224 -0
- package/dist/pr-dashboard.tui.js +8710 -0
- package/package.json +65 -4
- package/plugins/app/DashboardView.tsx +373 -0
- package/plugins/app/PRRow.tsx +241 -0
- package/plugins/app/StatusMessage.tsx +22 -0
- package/plugins/app/actions.tsx +25 -0
- package/plugins/app/config.ts +165 -0
- package/plugins/app/theme.ts +53 -0
- package/plugins/app/usePRData.ts +364 -0
- package/plugins/domain/format.ts +27 -0
- package/plugins/domain/messages.ts +183 -0
- package/plugins/domain/pr-filters.ts +40 -0
- package/plugins/domain/pr-links.ts +12 -0
- package/plugins/domain/pr-status.ts +128 -0
- package/plugins/domain/types.ts +94 -0
- package/plugins/infra/git.ts +416 -0
- package/plugins/infra/github-enterprise.ts +31 -0
- package/plugins/infra/loader.ts +356 -0
- package/plugins/infra/mappers.ts +93 -0
- package/plugins/infra/octokit.ts +131 -0
- package/plugins/infra/queries.ts +155 -0
- package/plugins/pr-dashboard.ts +8 -0
- package/plugins/pr-dashboard.tui.tsx +238 -0
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
// GraphQL query strings used by the PR dashboard loaders.
|
|
2
|
+
//
|
|
3
|
+
// Kept separate from loader.ts so the query surface is easy to audit
|
|
4
|
+
// (scope requirements, field selection) without scrolling through the
|
|
5
|
+
// orchestration code.
|
|
6
|
+
|
|
7
|
+
const PULL_REQUEST_FIELDS_BASE = `fragment DashboardPullRequestFields on PullRequest {
|
|
8
|
+
number
|
|
9
|
+
title
|
|
10
|
+
url
|
|
11
|
+
isDraft
|
|
12
|
+
state
|
|
13
|
+
headRefName
|
|
14
|
+
headRepositoryOwner { login }
|
|
15
|
+
author { login }
|
|
16
|
+
assignees(first: 100) {
|
|
17
|
+
nodes { login }
|
|
18
|
+
}
|
|
19
|
+
additions
|
|
20
|
+
deletions
|
|
21
|
+
baseRefName
|
|
22
|
+
mergeable
|
|
23
|
+
statusCheckRollup {
|
|
24
|
+
state
|
|
25
|
+
contexts(first: 100) {
|
|
26
|
+
totalCount
|
|
27
|
+
nodes {
|
|
28
|
+
__typename
|
|
29
|
+
... on CheckRun {
|
|
30
|
+
status
|
|
31
|
+
conclusion
|
|
32
|
+
}
|
|
33
|
+
... on StatusContext {
|
|
34
|
+
state
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
reviewThreads(first: 100) {
|
|
40
|
+
totalCount
|
|
41
|
+
nodes {
|
|
42
|
+
isResolved
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
reviewRequests(first: 100) {
|
|
46
|
+
nodes {
|
|
47
|
+
requestedReviewer {
|
|
48
|
+
... on User { login }
|
|
49
|
+
... on Team { slug }
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
latestReviews(first: 5) {
|
|
54
|
+
nodes {
|
|
55
|
+
author { login }
|
|
56
|
+
state
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}`
|
|
60
|
+
|
|
61
|
+
const PULL_REQUEST_STATUS_FIELDS = ` mergeStateStatus
|
|
62
|
+
reviewDecision`
|
|
63
|
+
|
|
64
|
+
const withPullRequestStatusFields = (fragment: string) =>
|
|
65
|
+
fragment.replace(" statusCheckRollup {", `${PULL_REQUEST_STATUS_FIELDS}\n statusCheckRollup {`)
|
|
66
|
+
|
|
67
|
+
const PULL_REQUEST_FIELDS = withPullRequestStatusFields(PULL_REQUEST_FIELDS_BASE)
|
|
68
|
+
|
|
69
|
+
// PRs for a repository (or one head branch) in the given GitHub states.
|
|
70
|
+
export const PULL_REQUESTS_QUERY = `query PullRequests($owner: String!, $name: String!, $states: [PullRequestState!]!, $head: String, $after: String, $first: Int!) {
|
|
71
|
+
viewer {
|
|
72
|
+
login
|
|
73
|
+
}
|
|
74
|
+
repository(owner: $owner, name: $name) {
|
|
75
|
+
pullRequests(first: $first, after: $after, states: $states, headRefName: $head, orderBy: {field: UPDATED_AT, direction: DESC}) {
|
|
76
|
+
totalCount
|
|
77
|
+
pageInfo {
|
|
78
|
+
hasNextPage
|
|
79
|
+
endCursor
|
|
80
|
+
}
|
|
81
|
+
nodes { ...DashboardPullRequestFields }
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
${PULL_REQUEST_FIELDS}`
|
|
86
|
+
|
|
87
|
+
// Older GHES versions may not expose these two fields. The loader retries
|
|
88
|
+
// once with this status-field-free query only when GraphQL reports them unknown.
|
|
89
|
+
export const PULL_REQUESTS_QUERY_LEGACY = `query PullRequests($owner: String!, $name: String!, $states: [PullRequestState!]!, $head: String, $after: String, $first: Int!) {
|
|
90
|
+
viewer {
|
|
91
|
+
login
|
|
92
|
+
}
|
|
93
|
+
repository(owner: $owner, name: $name) {
|
|
94
|
+
pullRequests(first: $first, after: $after, states: $states, headRefName: $head, orderBy: {field: UPDATED_AT, direction: DESC}) {
|
|
95
|
+
totalCount
|
|
96
|
+
pageInfo {
|
|
97
|
+
hasNextPage
|
|
98
|
+
endCursor
|
|
99
|
+
}
|
|
100
|
+
nodes { ...DashboardPullRequestFields }
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
${PULL_REQUEST_FIELDS_BASE}`
|
|
105
|
+
|
|
106
|
+
// GitHub doesn't expose author or assignee filters on Repository.pullRequests,
|
|
107
|
+
// so those scopes use issue search. A small recent PR connection supplements
|
|
108
|
+
// search while its index catches up.
|
|
109
|
+
export const PULL_REQUESTS_SEARCH_QUERY = `query SearchPullRequests($owner: String!, $name: String!, $states: [PullRequestState!]!, $searchQuery: String!, $after: String, $first: Int!, $recentPRsLimit: Int!, $includeRecentPRs: Boolean!) {
|
|
110
|
+
viewer {
|
|
111
|
+
login
|
|
112
|
+
}
|
|
113
|
+
repository(owner: $owner, name: $name) {
|
|
114
|
+
recentPullRequests: pullRequests(first: $recentPRsLimit, states: $states, orderBy: {field: CREATED_AT, direction: DESC}) @include(if: $includeRecentPRs) {
|
|
115
|
+
nodes { ...DashboardPullRequestFields }
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
search(query: $searchQuery, type: ISSUE, first: $first, after: $after) {
|
|
119
|
+
issueCount
|
|
120
|
+
pageInfo {
|
|
121
|
+
hasNextPage
|
|
122
|
+
endCursor
|
|
123
|
+
}
|
|
124
|
+
nodes {
|
|
125
|
+
... on PullRequest {
|
|
126
|
+
...DashboardPullRequestFields
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
${PULL_REQUEST_FIELDS}`
|
|
132
|
+
|
|
133
|
+
export const PULL_REQUESTS_SEARCH_QUERY_LEGACY = `query SearchPullRequests($owner: String!, $name: String!, $states: [PullRequestState!]!, $searchQuery: String!, $after: String, $first: Int!, $recentPRsLimit: Int!, $includeRecentPRs: Boolean!) {
|
|
134
|
+
viewer {
|
|
135
|
+
login
|
|
136
|
+
}
|
|
137
|
+
repository(owner: $owner, name: $name) {
|
|
138
|
+
recentPullRequests: pullRequests(first: $recentPRsLimit, states: $states, orderBy: {field: CREATED_AT, direction: DESC}) @include(if: $includeRecentPRs) {
|
|
139
|
+
nodes { ...DashboardPullRequestFields }
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
search(query: $searchQuery, type: ISSUE, first: $first, after: $after) {
|
|
143
|
+
issueCount
|
|
144
|
+
pageInfo {
|
|
145
|
+
hasNextPage
|
|
146
|
+
endCursor
|
|
147
|
+
}
|
|
148
|
+
nodes {
|
|
149
|
+
... on PullRequest {
|
|
150
|
+
...DashboardPullRequestFields
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
${PULL_REQUEST_FIELDS_BASE}`
|
|
@@ -0,0 +1,238 @@
|
|
|
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
|
+
pagination: {
|
|
35
|
+
listing: "open",
|
|
36
|
+
scope: "all",
|
|
37
|
+
scopeValue: null,
|
|
38
|
+
cursor: null,
|
|
39
|
+
hasMore: false,
|
|
40
|
+
totalCount: null,
|
|
41
|
+
pagesLoaded: 0,
|
|
42
|
+
searchResultsFetched: 0,
|
|
43
|
+
supplementalPRCount: 0,
|
|
44
|
+
loading: false,
|
|
45
|
+
limitReached: false,
|
|
46
|
+
},
|
|
47
|
+
})
|
|
48
|
+
const demoMode = process.env.OPENCODE_GITHUB_PR_DEMO === "1"
|
|
49
|
+
if (demoMode) {
|
|
50
|
+
const { demoDashboardState } = await import("../demo/fixtures")
|
|
51
|
+
setState(demoDashboardState())
|
|
52
|
+
}
|
|
53
|
+
const [selectedIdx, setSelectedIdx] = createSignal(0)
|
|
54
|
+
const [scope, setScope] = createSignal<PRScope>(options.defaultScope)
|
|
55
|
+
const [statusFilter, setStatusFilter] = createSignal<PRStatusFilter>(
|
|
56
|
+
options.defaultStatusFilter,
|
|
57
|
+
)
|
|
58
|
+
const visiblePRs = () =>
|
|
59
|
+
filterPRs(
|
|
60
|
+
state().prs,
|
|
61
|
+
scope(),
|
|
62
|
+
statusFilter(),
|
|
63
|
+
state().currentBranch,
|
|
64
|
+
state().viewerLogin,
|
|
65
|
+
)
|
|
66
|
+
const cycleScope = () => {
|
|
67
|
+
const nextScope = nextPRScope(scope())
|
|
68
|
+
setScope(nextScope)
|
|
69
|
+
setSelectedIdx(0)
|
|
70
|
+
if (demoMode) {
|
|
71
|
+
const currentState = state()
|
|
72
|
+
setState((s) => ({
|
|
73
|
+
...s,
|
|
74
|
+
pagination: {
|
|
75
|
+
...s.pagination,
|
|
76
|
+
scope: nextScope,
|
|
77
|
+
scopeValue: nextScope === "branch" ? s.currentBranch : null,
|
|
78
|
+
totalCount: filterPRs(
|
|
79
|
+
currentState.prs,
|
|
80
|
+
nextScope,
|
|
81
|
+
statusFilter(),
|
|
82
|
+
currentState.currentBranch,
|
|
83
|
+
currentState.viewerLogin,
|
|
84
|
+
).length,
|
|
85
|
+
},
|
|
86
|
+
}))
|
|
87
|
+
} else {
|
|
88
|
+
void dash.refresh()
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
const cycleStatus = () => {
|
|
92
|
+
const nextStatus = nextPRStatusFilter(statusFilter())
|
|
93
|
+
setStatusFilter(nextStatus)
|
|
94
|
+
setSelectedIdx(0)
|
|
95
|
+
// Each status is queried separately so GitHub applies the status filter.
|
|
96
|
+
if (demoMode) {
|
|
97
|
+
const currentState = state()
|
|
98
|
+
setState((s) => ({
|
|
99
|
+
...s,
|
|
100
|
+
pagination: {
|
|
101
|
+
...s.pagination,
|
|
102
|
+
listing: nextStatus,
|
|
103
|
+
totalCount: filterPRs(
|
|
104
|
+
currentState.prs,
|
|
105
|
+
scope(),
|
|
106
|
+
nextStatus,
|
|
107
|
+
currentState.currentBranch,
|
|
108
|
+
currentState.viewerLogin,
|
|
109
|
+
).length,
|
|
110
|
+
},
|
|
111
|
+
}))
|
|
112
|
+
} else {
|
|
113
|
+
void dash.refresh()
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const dash = demoMode
|
|
118
|
+
? { refresh: async () => {}, loadMore: async () => {} }
|
|
119
|
+
: useDashboard(
|
|
120
|
+
api,
|
|
121
|
+
state,
|
|
122
|
+
setState,
|
|
123
|
+
options.requestTimeoutMs,
|
|
124
|
+
options.pagesPerBatch,
|
|
125
|
+
statusFilter,
|
|
126
|
+
scope,
|
|
127
|
+
options.pageSize,
|
|
128
|
+
options.recentPRsLimit,
|
|
129
|
+
)
|
|
130
|
+
const dashboard: DashboardContext = {
|
|
131
|
+
state,
|
|
132
|
+
refresh: dash.refresh,
|
|
133
|
+
loadMore: dash.loadMore,
|
|
134
|
+
selectedIdx,
|
|
135
|
+
setSelectedIdx,
|
|
136
|
+
}
|
|
137
|
+
const actions = createActions(api, dashboard)
|
|
138
|
+
|
|
139
|
+
if (!demoMode) void dash.refresh()
|
|
140
|
+
|
|
141
|
+
const unregisterSlot = api.ui.slot({
|
|
142
|
+
append: "sidebar.content",
|
|
143
|
+
render: () => (
|
|
144
|
+
<DashboardView
|
|
145
|
+
theme={api.theme}
|
|
146
|
+
state={state()}
|
|
147
|
+
setSelectedIdx={setSelectedIdx}
|
|
148
|
+
onOpen={actions.openPR}
|
|
149
|
+
scope={scope()}
|
|
150
|
+
statusFilter={statusFilter()}
|
|
151
|
+
onCycleScope={cycleScope}
|
|
152
|
+
onCycleStatus={cycleStatus}
|
|
153
|
+
onLoadMore={dash.loadMore}
|
|
154
|
+
pageSize={options.pageSize}
|
|
155
|
+
colors={options.colors}
|
|
156
|
+
icons={options.icons}
|
|
157
|
+
spacing={options.spacing}
|
|
158
|
+
showSingleStatusCount={options.showSingleStatusCount}
|
|
159
|
+
/>
|
|
160
|
+
),
|
|
161
|
+
})
|
|
162
|
+
// OpenCode 2.0 provides Keymap.Provider through the TUI's Solid render
|
|
163
|
+
// context. Register this from a slot render rather than setup so the
|
|
164
|
+
// provider is present on early V2 host releases as well. Keymap.createLayer
|
|
165
|
+
// returns void and owns its useBindings cleanup through this Solid owner, so
|
|
166
|
+
// tearing down the app slot also tears down the layer.
|
|
167
|
+
let keymapRegistered = false
|
|
168
|
+
const unregisterKeymapSlot = api.ui.slot({
|
|
169
|
+
append: "app",
|
|
170
|
+
render: () => {
|
|
171
|
+
if (!keymapRegistered) {
|
|
172
|
+
api.keymap.layer(() => ({
|
|
173
|
+
mode: "global",
|
|
174
|
+
commands: [
|
|
175
|
+
{
|
|
176
|
+
id: command.refresh,
|
|
177
|
+
title: "PRs: Refresh dashboard",
|
|
178
|
+
group: "PR Dashboard",
|
|
179
|
+
palette: true,
|
|
180
|
+
slash: { name: "pr-refresh" },
|
|
181
|
+
run() {
|
|
182
|
+
void dash.refresh().then(() => {
|
|
183
|
+
const current = state()
|
|
184
|
+
if (current.errorKind === "rate-limit") {
|
|
185
|
+
api.ui.toast.show({
|
|
186
|
+
variant: "info",
|
|
187
|
+
message: `PR refresh paused: ${current.error ?? "rate limit active"}`,
|
|
188
|
+
duration: 5000,
|
|
189
|
+
})
|
|
190
|
+
return
|
|
191
|
+
}
|
|
192
|
+
api.ui.toast.show({
|
|
193
|
+
variant: "info",
|
|
194
|
+
message: "Refreshing PRs…",
|
|
195
|
+
duration: 1200,
|
|
196
|
+
})
|
|
197
|
+
})
|
|
198
|
+
},
|
|
199
|
+
},
|
|
200
|
+
{
|
|
201
|
+
id: command.open,
|
|
202
|
+
title: "PRs: Open selected in browser",
|
|
203
|
+
group: "PR Dashboard",
|
|
204
|
+
palette: true,
|
|
205
|
+
slash: { name: "pr-open" },
|
|
206
|
+
enabled: () => visiblePRs().length > 0,
|
|
207
|
+
run() {
|
|
208
|
+
const pr = visiblePRs()[selectedIdx()]
|
|
209
|
+
if (pr) void actions.openPR(pr.number)
|
|
210
|
+
},
|
|
211
|
+
},
|
|
212
|
+
],
|
|
213
|
+
}))
|
|
214
|
+
keymapRegistered = true
|
|
215
|
+
}
|
|
216
|
+
return null
|
|
217
|
+
},
|
|
218
|
+
})
|
|
219
|
+
|
|
220
|
+
const stopOnIdle = api.data.on("session.idle", () => {
|
|
221
|
+
void dash.refresh()
|
|
222
|
+
})
|
|
223
|
+
const interval = setInterval(() => {
|
|
224
|
+
if (api.ui.router.current().type === "session") void dash.refresh()
|
|
225
|
+
}, options.refreshIntervalMs)
|
|
226
|
+
|
|
227
|
+
return () => {
|
|
228
|
+
clearInterval(interval)
|
|
229
|
+
stopOnIdle()
|
|
230
|
+
unregisterSlot()
|
|
231
|
+
unregisterKeymapSlot()
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
export default Plugin.define({
|
|
236
|
+
id: "opencode-github-pr.tui",
|
|
237
|
+
setup,
|
|
238
|
+
})
|