opencode-github-pr 0.1.0 → 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/README.md +168 -59
- package/demo/fixtures.ts +74 -8
- package/dist/pr-dashboard.tui.js +8710 -0
- package/package.json +20 -11
- package/plugins/app/DashboardView.tsx +166 -83
- package/plugins/app/PRRow.tsx +86 -54
- package/plugins/app/StatusMessage.tsx +22 -0
- package/plugins/app/config.ts +90 -10
- package/plugins/app/theme.ts +1 -10
- package/plugins/app/usePRData.ts +256 -85
- package/plugins/domain/format.ts +11 -22
- package/plugins/domain/messages.ts +34 -12
- package/plugins/domain/pr-status.ts +23 -22
- package/plugins/domain/types.ts +23 -6
- package/plugins/infra/git.ts +287 -27
- package/plugins/infra/loader.ts +274 -41
- package/plugins/infra/mappers.ts +25 -49
- package/plugins/infra/octokit.ts +33 -17
- package/plugins/infra/queries.ts +137 -51
- package/plugins/pr-dashboard.tui.tsx +124 -40
- package/demo/demo.gif +0 -0
- package/plugins/domain/login.ts +0 -33
package/plugins/infra/queries.ts
CHANGED
|
@@ -4,66 +4,152 @@
|
|
|
4
4
|
// (scope requirements, field selection) without scrolling through the
|
|
5
5
|
// orchestration code.
|
|
6
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
|
+
|
|
7
69
|
// PRs for a repository (or one head branch) in the given GitHub states.
|
|
8
|
-
export const PULL_REQUESTS_QUERY = `query PullRequests($owner: String!, $name: String!, $states: [PullRequestState!]!, $head: String, $after: String) {
|
|
70
|
+
export const PULL_REQUESTS_QUERY = `query PullRequests($owner: String!, $name: String!, $states: [PullRequestState!]!, $head: String, $after: String, $first: Int!) {
|
|
9
71
|
viewer {
|
|
10
72
|
login
|
|
11
73
|
}
|
|
12
74
|
repository(owner: $owner, name: $name) {
|
|
13
|
-
pullRequests(first:
|
|
75
|
+
pullRequests(first: $first, after: $after, states: $states, headRefName: $head, orderBy: {field: UPDATED_AT, direction: DESC}) {
|
|
76
|
+
totalCount
|
|
14
77
|
pageInfo {
|
|
15
78
|
hasNextPage
|
|
16
79
|
endCursor
|
|
17
80
|
}
|
|
18
|
-
nodes {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
nodes {
|
|
37
|
-
__typename
|
|
38
|
-
... on CheckRun {
|
|
39
|
-
status
|
|
40
|
-
conclusion
|
|
41
|
-
}
|
|
42
|
-
... on StatusContext {
|
|
43
|
-
state
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
reviewThreads(first: 100) {
|
|
49
|
-
nodes {
|
|
50
|
-
isResolved
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
reviewRequests(first: 5) {
|
|
54
|
-
nodes {
|
|
55
|
-
requestedReviewer {
|
|
56
|
-
... on User { login }
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
latestReviews(first: 5) {
|
|
61
|
-
nodes {
|
|
62
|
-
author { login }
|
|
63
|
-
state
|
|
64
|
-
}
|
|
65
|
-
}
|
|
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
|
|
66
99
|
}
|
|
100
|
+
nodes { ...DashboardPullRequestFields }
|
|
67
101
|
}
|
|
68
102
|
}
|
|
69
|
-
}
|
|
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}`
|
|
@@ -31,8 +31,19 @@ async function setup(api: TuiPluginContext) {
|
|
|
31
31
|
currentBranch: null,
|
|
32
32
|
viewerLogin: null,
|
|
33
33
|
fetchedAt: null,
|
|
34
|
-
|
|
35
|
-
|
|
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
|
+
},
|
|
36
47
|
})
|
|
37
48
|
const demoMode = process.env.OPENCODE_GITHUB_PR_DEMO === "1"
|
|
38
49
|
if (demoMode) {
|
|
@@ -41,34 +52,85 @@ async function setup(api: TuiPluginContext) {
|
|
|
41
52
|
}
|
|
42
53
|
const [selectedIdx, setSelectedIdx] = createSignal(0)
|
|
43
54
|
const [scope, setScope] = createSignal<PRScope>(options.defaultScope)
|
|
44
|
-
const [statusFilter, setStatusFilter] = createSignal<PRStatusFilter>(
|
|
55
|
+
const [statusFilter, setStatusFilter] = createSignal<PRStatusFilter>(
|
|
56
|
+
options.defaultStatusFilter,
|
|
57
|
+
)
|
|
45
58
|
const visiblePRs = () =>
|
|
46
|
-
filterPRs(
|
|
59
|
+
filterPRs(
|
|
60
|
+
state().prs,
|
|
61
|
+
scope(),
|
|
62
|
+
statusFilter(),
|
|
63
|
+
state().currentBranch,
|
|
64
|
+
state().viewerLogin,
|
|
65
|
+
)
|
|
47
66
|
const cycleScope = () => {
|
|
48
|
-
|
|
67
|
+
const nextScope = nextPRScope(scope())
|
|
68
|
+
setScope(nextScope)
|
|
49
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
|
+
}
|
|
50
90
|
}
|
|
51
91
|
const cycleStatus = () => {
|
|
52
|
-
|
|
92
|
+
const nextStatus = nextPRStatusFilter(statusFilter())
|
|
93
|
+
setStatusFilter(nextStatus)
|
|
53
94
|
setSelectedIdx(0)
|
|
54
|
-
//
|
|
55
|
-
if (
|
|
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
|
+
}
|
|
56
115
|
}
|
|
57
116
|
|
|
58
117
|
const dash = demoMode
|
|
59
|
-
? { refresh: async () => {},
|
|
118
|
+
? { refresh: async () => {}, loadMore: async () => {} }
|
|
60
119
|
: useDashboard(
|
|
61
120
|
api,
|
|
62
121
|
state,
|
|
63
122
|
setState,
|
|
64
123
|
options.requestTimeoutMs,
|
|
65
|
-
options.
|
|
66
|
-
|
|
124
|
+
options.pagesPerBatch,
|
|
125
|
+
statusFilter,
|
|
126
|
+
scope,
|
|
127
|
+
options.pageSize,
|
|
128
|
+
options.recentPRsLimit,
|
|
67
129
|
)
|
|
68
130
|
const dashboard: DashboardContext = {
|
|
69
131
|
state,
|
|
70
132
|
refresh: dash.refresh,
|
|
71
|
-
|
|
133
|
+
loadMore: dash.loadMore,
|
|
72
134
|
selectedIdx,
|
|
73
135
|
setSelectedIdx,
|
|
74
136
|
}
|
|
@@ -88,47 +150,69 @@ async function setup(api: TuiPluginContext) {
|
|
|
88
150
|
statusFilter={statusFilter()}
|
|
89
151
|
onCycleScope={cycleScope}
|
|
90
152
|
onCycleStatus={cycleStatus}
|
|
153
|
+
onLoadMore={dash.loadMore}
|
|
91
154
|
pageSize={options.pageSize}
|
|
92
|
-
maxPRPages={options.maxPRPages}
|
|
93
155
|
colors={options.colors}
|
|
94
156
|
icons={options.icons}
|
|
157
|
+
spacing={options.spacing}
|
|
158
|
+
showSingleStatusCount={options.showSingleStatusCount}
|
|
95
159
|
/>
|
|
96
160
|
),
|
|
97
161
|
})
|
|
98
162
|
// OpenCode 2.0 provides Keymap.Provider through the TUI's Solid render
|
|
99
163
|
// context. Register this from a slot render rather than setup so the
|
|
100
|
-
// provider is present on early V2 host releases as well.
|
|
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
|
|
101
168
|
const unregisterKeymapSlot = api.ui.slot({
|
|
102
169
|
append: "app",
|
|
103
170
|
render: () => {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
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
|
+
},
|
|
116
199
|
},
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
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
|
+
},
|
|
128
211
|
},
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
212
|
+
],
|
|
213
|
+
}))
|
|
214
|
+
keymapRegistered = true
|
|
215
|
+
}
|
|
132
216
|
return null
|
|
133
217
|
},
|
|
134
218
|
})
|
package/demo/demo.gif
DELETED
|
Binary file
|
package/plugins/domain/login.ts
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
// Login display helpers and bot-account aliases used by the TUI sidebar.
|
|
2
|
-
|
|
3
|
-
export const BOT_ALIASES: Record<string, string> = {
|
|
4
|
-
"copilot-pull-request-reviewer": "copilot",
|
|
5
|
-
"copilot-swe-agent": "copilot",
|
|
6
|
-
"copilot": "copilot",
|
|
7
|
-
"dependabot": "dependabot",
|
|
8
|
-
"dependabot-preview": "dependabot",
|
|
9
|
-
"github-actions": "github-actions",
|
|
10
|
-
"renovate": "renovate",
|
|
11
|
-
"renovate-bot": "renovate",
|
|
12
|
-
"graphite-app": "graphite",
|
|
13
|
-
"graphite-ci": "graphite",
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export function displayLogin(login: string): string {
|
|
17
|
-
const lower = login.toLowerCase()
|
|
18
|
-
if (BOT_ALIASES[lower]) return BOT_ALIASES[lower]
|
|
19
|
-
if (lower.endsWith("[bot]")) {
|
|
20
|
-
const base = lower.slice(0, -5)
|
|
21
|
-
return BOT_ALIASES[base] ?? base
|
|
22
|
-
}
|
|
23
|
-
if (lower.endsWith("-bot")) {
|
|
24
|
-
const base = lower.slice(0, -4)
|
|
25
|
-
return BOT_ALIASES[base] ?? base
|
|
26
|
-
}
|
|
27
|
-
return login
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export function ellipsize(name: string, maxLen = 9): string {
|
|
31
|
-
if (name.length <= maxLen) return name
|
|
32
|
-
return name.slice(0, 4) + "…" + name.slice(-4)
|
|
33
|
-
}
|