dsh-github-console 0.0.0-stage → 0.4.1
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 +155 -2
- package/assets/icon-180.png +0 -0
- package/assets/icon-512.png +0 -0
- package/assets/icon-96.png +0 -0
- package/client.js +1546 -0
- package/cordis.patch.yml +20 -0
- package/icon.svg +7 -0
- package/index.js +4400 -0
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +47 -4
package/client.js
ADDED
|
@@ -0,0 +1,1546 @@
|
|
|
1
|
+
window.__ModuleLoader__.load({
|
|
2
|
+
id: 'dsh-github-console',
|
|
3
|
+
factory(require) {
|
|
4
|
+
const React = require('react')
|
|
5
|
+
const h = React.createElement
|
|
6
|
+
const { useState, useEffect, useRef, useCallback, useMemo } = React
|
|
7
|
+
|
|
8
|
+
function readBridge() {
|
|
9
|
+
return typeof window === 'undefined' ? undefined : window.__DGH_BRIDGE__
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// The Host injects the bridge into the page head; if this module evaluates
|
|
13
|
+
// first, keep looking briefly instead of failing the whole panel.
|
|
14
|
+
function useBridge() {
|
|
15
|
+
const [bridge, setBridge] = useState(() => readBridge())
|
|
16
|
+
useEffect(() => {
|
|
17
|
+
if (bridge) return undefined
|
|
18
|
+
let tries = 0
|
|
19
|
+
const timer = setInterval(() => {
|
|
20
|
+
tries += 1
|
|
21
|
+
const next = readBridge()
|
|
22
|
+
if (next || tries > 20) {
|
|
23
|
+
clearInterval(timer)
|
|
24
|
+
if (next) setBridge(next)
|
|
25
|
+
}
|
|
26
|
+
}, 300)
|
|
27
|
+
return () => clearInterval(timer)
|
|
28
|
+
}, [bridge])
|
|
29
|
+
return bridge
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const CODE_HINT = {
|
|
33
|
+
AUTH_MISSING: '还没有可用的 GitHub App 或 installation',
|
|
34
|
+
AUTH_EXPIRED: '凭据已失效,需要重新注册或安装 App',
|
|
35
|
+
SCOPE_DENIED: 'App 权限不足,到 GitHub 的 App 设置里补授权',
|
|
36
|
+
RATE_LIMITED: '触发 GitHub 限流,稍后再试',
|
|
37
|
+
NOT_FOUND: '仓库或文件不存在,或未授权给当前 App',
|
|
38
|
+
REF_CONFLICT: '远端文件已被修改,请重新读取后再提交',
|
|
39
|
+
INVALID: 'GitHub 拒绝了这次请求(参数或状态不合法)',
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function makeApi(bridge) {
|
|
43
|
+
return async function call(route, body) {
|
|
44
|
+
const response = await fetch(`${bridge.base}/github-console/api/${route}`, {
|
|
45
|
+
method: 'POST',
|
|
46
|
+
headers: { Authorization: `Bearer ${bridge.token}`, 'Content-Type': 'application/json' },
|
|
47
|
+
body: JSON.stringify(body || {}),
|
|
48
|
+
})
|
|
49
|
+
const text = await response.text()
|
|
50
|
+
let data = null
|
|
51
|
+
try {
|
|
52
|
+
data = text ? JSON.parse(text) : null
|
|
53
|
+
} catch {
|
|
54
|
+
data = { error: text }
|
|
55
|
+
}
|
|
56
|
+
if (!response.ok) {
|
|
57
|
+
const code = data && data.code ? String(data.code) : ''
|
|
58
|
+
const message = data && data.error ? String(data.error) : `HTTP ${response.status}`
|
|
59
|
+
const hint = CODE_HINT[code]
|
|
60
|
+
const failure = new Error(hint ? `${hint}:${message}` : message)
|
|
61
|
+
failure.code = code
|
|
62
|
+
failure.status = response.status
|
|
63
|
+
throw failure
|
|
64
|
+
}
|
|
65
|
+
return data
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const S = {
|
|
70
|
+
page: { height: '100%', overflowY: 'auto', overflowX: 'hidden', overscrollBehavior: 'contain', background: 'var(--dsw-alias-bg-base)', color: 'var(--dsw-alias-label-primary)' },
|
|
71
|
+
inner: { padding: '18px 20px 40px', maxWidth: 900, paddingTop: 'calc(var(--dsh-frame-top-clearance, 0px) + 12px)' },
|
|
72
|
+
header: { display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: 10, marginBottom: 12 },
|
|
73
|
+
title: { margin: 0, fontSize: 18, fontWeight: 600 },
|
|
74
|
+
sub: { marginTop: 3, fontSize: 12, color: 'var(--dsw-alias-label-secondary)' },
|
|
75
|
+
tabs: { display: 'flex', gap: 4, margin: '10px 0 14px', borderBottom: '1px solid var(--dsw-alias-border-l1)', flexWrap: 'wrap' },
|
|
76
|
+
card: { border: '1px solid var(--dsw-alias-border-l1)', borderRadius: 10, background: 'var(--dsw-alias-bg-layer-1)', padding: '13px 15px', marginBottom: 12 },
|
|
77
|
+
line: { display: 'flex', gap: 10, padding: '3px 0', fontSize: 13, alignItems: 'baseline' },
|
|
78
|
+
label: { width: 88, flex: '0 0 auto', color: 'var(--dsw-alias-label-secondary)', fontSize: 12 },
|
|
79
|
+
value: { flex: 1, minWidth: 0, overflowWrap: 'anywhere' },
|
|
80
|
+
button: { border: '1px solid var(--dsw-alias-border-l2)', background: 'transparent', color: 'var(--dsw-alias-label-primary)', borderRadius: 8, padding: '5px 12px', fontSize: 13, cursor: 'pointer' },
|
|
81
|
+
primary: { border: '1px solid #3E6FD8', background: '#3E6FD8', color: '#fff', borderRadius: 8, padding: '7px 16px', fontSize: 13, fontWeight: 500, cursor: 'pointer' },
|
|
82
|
+
danger: { border: '1px solid var(--dsw-alias-border-l2)', background: 'transparent', color: 'var(--dsw-alias-state-error-primary)', borderRadius: 8, padding: '5px 12px', fontSize: 13, cursor: 'pointer' },
|
|
83
|
+
input: { width: '100%', boxSizing: 'border-box', padding: '7px 10px', borderRadius: 8, border: '1px solid var(--dsw-alias-border-l2)', background: 'var(--dsw-alias-bg-base)', color: 'var(--dsw-alias-label-primary)', fontSize: 13 },
|
|
84
|
+
row: { display: 'flex', alignItems: 'center', gap: 8, padding: '7px 6px', borderBottom: '1px solid var(--dsw-alias-border-l1)', fontSize: 13, borderRadius: 6 },
|
|
85
|
+
name: { flex: 1, minWidth: 0, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' },
|
|
86
|
+
meta: { fontSize: 12, color: 'var(--dsw-alias-label-secondary)', flex: '0 0 auto' },
|
|
87
|
+
badge: (ok) => ({ fontSize: 11, padding: '2px 9px', borderRadius: 999, border: '1px solid var(--dsw-alias-border-l1)', color: ok ? 'var(--dsw-alias-state-success-primary)' : 'var(--dsw-alias-label-secondary)' }),
|
|
88
|
+
error: { color: 'var(--dsw-alias-state-error-primary)', fontSize: 13, margin: '8px 0', lineHeight: 1.6 },
|
|
89
|
+
notice: { color: 'var(--dsw-alias-label-secondary)', fontSize: 12, margin: '6px 0', lineHeight: 1.7 },
|
|
90
|
+
pre: { margin: 0, padding: '10px 12px', background: 'var(--dsw-alias-bg-layer-2)', borderRadius: 8, fontSize: 12, lineHeight: 1.6, overflow: 'auto', maxHeight: 380, whiteSpace: 'pre-wrap', overflowWrap: 'anywhere' },
|
|
91
|
+
warn: { color: 'var(--dsw-alias-state-warn-primary)', fontSize: 13, margin: '6px 0', lineHeight: 1.6 },
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function Tab({ active, onClick, children }) {
|
|
95
|
+
return h(
|
|
96
|
+
'button',
|
|
97
|
+
{
|
|
98
|
+
onClick,
|
|
99
|
+
role: 'tab',
|
|
100
|
+
'aria-selected': active,
|
|
101
|
+
style: {
|
|
102
|
+
border: 'none',
|
|
103
|
+
background: 'transparent',
|
|
104
|
+
padding: '7px 11px',
|
|
105
|
+
fontSize: 13,
|
|
106
|
+
cursor: 'pointer',
|
|
107
|
+
color: active ? 'var(--dsw-alias-brand-primary)' : 'var(--dsw-alias-label-secondary)',
|
|
108
|
+
borderBottom: `2px solid ${active ? 'var(--dsw-alias-brand-primary)' : 'transparent'}`,
|
|
109
|
+
marginBottom: -1,
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
children,
|
|
113
|
+
)
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function useAsync() {
|
|
117
|
+
const [busy, setBusy] = useState('')
|
|
118
|
+
const [error, setError] = useState('')
|
|
119
|
+
const run = useCallback(async (label, fn) => {
|
|
120
|
+
setBusy(label)
|
|
121
|
+
setError('')
|
|
122
|
+
try {
|
|
123
|
+
return await fn()
|
|
124
|
+
} catch (failure) {
|
|
125
|
+
setError(failure instanceof Error ? failure.message : String(failure))
|
|
126
|
+
return undefined
|
|
127
|
+
} finally {
|
|
128
|
+
setBusy('')
|
|
129
|
+
}
|
|
130
|
+
}, [])
|
|
131
|
+
// Background refresh: it must not touch busy or the error banner, or a
|
|
132
|
+
// 5-second poll would clear a just-shown failure and unlock a button whose
|
|
133
|
+
// action is still running.
|
|
134
|
+
const runSilent = useCallback(async (fn) => {
|
|
135
|
+
try {
|
|
136
|
+
return await fn()
|
|
137
|
+
} catch {
|
|
138
|
+
return undefined
|
|
139
|
+
}
|
|
140
|
+
}, [])
|
|
141
|
+
return { busy, error, setError, run, runSilent }
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
const LEVEL_MARK = { pass: '✓', warn: '!', block: '✕', info: '·' }
|
|
145
|
+
const PROBE_STATE = { listed: '已收录', absent: '未收录', unknown: '未知' }
|
|
146
|
+
const NPM_PHASE = {
|
|
147
|
+
'needs-first-publish': '第一步:先在 npm 上发一次',
|
|
148
|
+
'needs-workflow': '第二步:生成发布 workflow',
|
|
149
|
+
ready: '已就绪:可以走 OIDC 自动发布',
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// Selecting the text is the fallback when the clipboard API is blocked.
|
|
153
|
+
function CopyValue({ value, label }) {
|
|
154
|
+
const [copied, setCopied] = useState(false)
|
|
155
|
+
return h(
|
|
156
|
+
'span',
|
|
157
|
+
{ style: { display: 'inline-flex', gap: 6, alignItems: 'center', flexWrap: 'wrap', margin: '2px 0' } },
|
|
158
|
+
label ? h('span', { style: { fontSize: 12, color: 'var(--dsw-alias-label-secondary)' } }, label) : null,
|
|
159
|
+
h('code', { style: { fontSize: 12, background: 'var(--dsw-alias-bg-layer-2)', padding: '1px 6px', borderRadius: 4, overflowWrap: 'anywhere' } }, value),
|
|
160
|
+
h(
|
|
161
|
+
'button',
|
|
162
|
+
{
|
|
163
|
+
style: { ...S.button, padding: '1px 8px', fontSize: 11 },
|
|
164
|
+
onClick: async () => {
|
|
165
|
+
try {
|
|
166
|
+
await navigator.clipboard.writeText(value)
|
|
167
|
+
setCopied(true)
|
|
168
|
+
setTimeout(() => setCopied(false), 1500)
|
|
169
|
+
} catch {
|
|
170
|
+
setCopied(false)
|
|
171
|
+
}
|
|
172
|
+
},
|
|
173
|
+
},
|
|
174
|
+
copied ? '已复制' : '复制',
|
|
175
|
+
),
|
|
176
|
+
)
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
function PreflightView({ report }) {
|
|
180
|
+
if (!report) return null
|
|
181
|
+
return h(
|
|
182
|
+
'div',
|
|
183
|
+
{ style: S.card },
|
|
184
|
+
h('div', { style: { ...S.line, justifyContent: 'space-between' } },
|
|
185
|
+
h('strong', { style: { fontSize: 13 } }, report.ready ? '体检通过,可以发布' : '体检有阻断项'),
|
|
186
|
+
h('span', { style: S.meta, maxWidth: 260, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }, report.dir),
|
|
187
|
+
),
|
|
188
|
+
report.checks.map((check) =>
|
|
189
|
+
h(
|
|
190
|
+
'div',
|
|
191
|
+
{ key: check.id, style: S.line },
|
|
192
|
+
h('span', { style: { ...S.meta, width: 14, flex: '0 0 auto', color: check.level === 'block' ? 'var(--dsw-alias-state-error-primary)' : check.level === 'warn' ? 'var(--dsw-alias-state-warn-primary)' : 'var(--dsw-alias-label-secondary)' } }, LEVEL_MARK[check.level] || '·'),
|
|
193
|
+
h('span', { style: S.value }, check.title, check.detail ? h('span', { style: S.meta }, ` — ${check.detail}`) : null),
|
|
194
|
+
),
|
|
195
|
+
),
|
|
196
|
+
)
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
function StepsView({ job }) {
|
|
200
|
+
if (!job) return null
|
|
201
|
+
const colors = { pending: 'var(--dsw-alias-label-secondary)', running: 'var(--dsw-alias-brand-primary)', done: 'var(--dsw-alias-state-success-primary)', failed: 'var(--dsw-alias-state-error-primary)' }
|
|
202
|
+
const marks = { pending: '○', running: '◐', done: '✓', failed: '✕' }
|
|
203
|
+
return h(
|
|
204
|
+
'div',
|
|
205
|
+
{ style: S.card },
|
|
206
|
+
h('div', { style: { ...S.line, justifyContent: 'space-between' } },
|
|
207
|
+
h('strong', { style: { fontSize: 13 } }, job.finishedAt ? (job.ok ? '发布完成' : '发布未完成') : '发布进行中'),
|
|
208
|
+
h('span', { style: S.meta }, job.createdAt ? new Date(job.createdAt).toLocaleTimeString() : ''),
|
|
209
|
+
),
|
|
210
|
+
job.steps.map((item) =>
|
|
211
|
+
h(
|
|
212
|
+
'div',
|
|
213
|
+
{ key: item.id, style: S.line },
|
|
214
|
+
h('span', { style: { ...S.meta, width: 14, flex: '0 0 auto', color: colors[item.state] || 'inherit' } }, marks[item.state] || '·'),
|
|
215
|
+
h('span', { style: { width: 88, flex: '0 0 auto' } }, item.title),
|
|
216
|
+
h('span', { style: { ...S.value, color: 'var(--dsw-alias-label-secondary)', fontSize: 12 } }, item.detail || ''),
|
|
217
|
+
),
|
|
218
|
+
),
|
|
219
|
+
job.releaseUrl
|
|
220
|
+
? h('a', { href: job.releaseUrl, target: '_blank', rel: 'noreferrer', style: { fontSize: 12, color: 'var(--dsw-alias-brand-primary)' } }, '打开 Release')
|
|
221
|
+
: null,
|
|
222
|
+
)
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
function Console() {
|
|
226
|
+
const bridge = useBridge()
|
|
227
|
+
const api = useMemo(() => (bridge ? makeApi(bridge) : null), [bridge])
|
|
228
|
+
const [tab, setTab] = useState('status')
|
|
229
|
+
const [status, setStatus] = useState(null)
|
|
230
|
+
const { busy, error, setError, run, runSilent } = useAsync()
|
|
231
|
+
|
|
232
|
+
const [repos, setRepos] = useState([])
|
|
233
|
+
const [repoQuery, setRepoQuery] = useState('')
|
|
234
|
+
const [selectedRepo, setSelectedRepo] = useState('')
|
|
235
|
+
const [tree, setTree] = useState(null)
|
|
236
|
+
const [file, setFile] = useState(null)
|
|
237
|
+
const [fileError, setFileError] = useState('')
|
|
238
|
+
const [editing, setEditing] = useState(false)
|
|
239
|
+
const [draft, setDraft] = useState('')
|
|
240
|
+
const [commitMessage, setCommitMessage] = useState('')
|
|
241
|
+
|
|
242
|
+
const [inbox, setInbox] = useState({ issues: null, pulls: null, runs: null, errors: [] })
|
|
243
|
+
const [pullDetail, setPullDetail] = useState(null)
|
|
244
|
+
const [commentDraft, setCommentDraft] = useState('')
|
|
245
|
+
const [reviewNote, setReviewNote] = useState('')
|
|
246
|
+
const [inlineTarget, setInlineTarget] = useState('')
|
|
247
|
+
const [runLog, setRunLog] = useState(null)
|
|
248
|
+
|
|
249
|
+
const [publishDir, setPublishDir] = useState('')
|
|
250
|
+
const [report, setReport] = useState(null)
|
|
251
|
+
const [job, setJob] = useState(null)
|
|
252
|
+
|
|
253
|
+
const [probeName, setProbeName] = useState('')
|
|
254
|
+
const [probeVersion, setProbeVersion] = useState('')
|
|
255
|
+
const [probe, setProbe] = useState(null)
|
|
256
|
+
const [npmRun, setNpmRun] = useState(null)
|
|
257
|
+
const [npmState, setNpmState] = useState(null)
|
|
258
|
+
const [releaseAsset, setReleaseAsset] = useState(null)
|
|
259
|
+
const [readiness, setReadiness] = useState(null)
|
|
260
|
+
const [marketIndex, setMarketIndex] = useState(null)
|
|
261
|
+
const [marketAttach, setMarketAttach] = useState(null)
|
|
262
|
+
const [reposLoaded, setReposLoaded] = useState(false)
|
|
263
|
+
const [reposTotal, setReposTotal] = useState(0)
|
|
264
|
+
const [patInput, setPatInput] = useState('')
|
|
265
|
+
const [authBusy, setAuthBusy] = useState('')
|
|
266
|
+
const [authMessage, setAuthMessage] = useState('')
|
|
267
|
+
const [device, setDevice] = useState(null)
|
|
268
|
+
const [setupUrl, setSetupUrl] = useState('')
|
|
269
|
+
const [discovered, setDiscovered] = useState(null)
|
|
270
|
+
const [discoverError, setDiscoverError] = useState('')
|
|
271
|
+
const [discoverRoot, setDiscoverRoot] = useState('')
|
|
272
|
+
const [repoTarget, setRepoTarget] = useState('')
|
|
273
|
+
const [repoTargetEdited, setRepoTargetEdited] = useState(false)
|
|
274
|
+
const [preflightingDir, setPreflightingDir] = useState('')
|
|
275
|
+
const [showAdvanced, setShowAdvanced] = useState(false)
|
|
276
|
+
const [publishBranch, setPublishBranch] = useState('')
|
|
277
|
+
const [publishNotes, setPublishNotes] = useState('')
|
|
278
|
+
|
|
279
|
+
const refreshStatus = useCallback(async () => {
|
|
280
|
+
if (!api) return
|
|
281
|
+
const next = await run('status', () => api('status'))
|
|
282
|
+
if (next) setStatus(next)
|
|
283
|
+
}, [api, run])
|
|
284
|
+
|
|
285
|
+
// Background poll: silent, so it never clears a failure banner or unlocks
|
|
286
|
+
// a button whose action is still in flight.
|
|
287
|
+
const refreshStatusSilently = useCallback(async () => {
|
|
288
|
+
if (!api) return
|
|
289
|
+
const next = await runSilent(() => api('status'))
|
|
290
|
+
if (next) setStatus(next)
|
|
291
|
+
}, [api, runSilent])
|
|
292
|
+
|
|
293
|
+
useEffect(() => {
|
|
294
|
+
if (!api) return
|
|
295
|
+
void refreshStatus()
|
|
296
|
+
}, [api, refreshStatus])
|
|
297
|
+
|
|
298
|
+
// Re-attach to a publish job that was still running when the panel unmounted.
|
|
299
|
+
useEffect(() => {
|
|
300
|
+
if (!api) return
|
|
301
|
+
void (async () => {
|
|
302
|
+
const data = await runSilent(() => api('publish/jobs'))
|
|
303
|
+
const items = data && Array.isArray(data.items) ? data.items : []
|
|
304
|
+
const latest = items[items.length - 1]
|
|
305
|
+
if (latest) setJob(latest)
|
|
306
|
+
})()
|
|
307
|
+
}, [api, runSilent])
|
|
308
|
+
|
|
309
|
+
// Local discovery needs no GitHub sign-in, so the panel has something
|
|
310
|
+
// useful to show on first open even before an App exists.
|
|
311
|
+
useEffect(() => {
|
|
312
|
+
if (!api) return
|
|
313
|
+
let cancelled = false
|
|
314
|
+
void (async () => {
|
|
315
|
+
const data = await runSilent(() => api('discover'))
|
|
316
|
+
if (cancelled) return
|
|
317
|
+
if (!data) {
|
|
318
|
+
setDiscoverError('扫描失败:Host 没有返回结果。可以在卡片里手填一个父目录再试。')
|
|
319
|
+
return
|
|
320
|
+
}
|
|
321
|
+
setDiscovered(data)
|
|
322
|
+
const first = data.items && data.items[0]
|
|
323
|
+
if (first) {
|
|
324
|
+
setPublishDir((current) => current || first.dir)
|
|
325
|
+
setRepoTarget((current) => (current || repoTargetEdited ? current : first.suggestedRepo))
|
|
326
|
+
setProbeName((current) => current || first.name)
|
|
327
|
+
}
|
|
328
|
+
})()
|
|
329
|
+
return () => {
|
|
330
|
+
cancelled = true
|
|
331
|
+
}
|
|
332
|
+
}, [api, runSilent, repoTargetEdited])
|
|
333
|
+
|
|
334
|
+
// Poll fast while the chain is incomplete, and slowly afterwards so an
|
|
335
|
+
// uninstall on GitHub is noticed instead of freezing the panel at 已连接.
|
|
336
|
+
useEffect(() => {
|
|
337
|
+
if (!api) return undefined
|
|
338
|
+
const interval = status && status.installation ? 30000 : 5000
|
|
339
|
+
const timer = setInterval(() => {
|
|
340
|
+
void refreshStatusSilently()
|
|
341
|
+
}, interval)
|
|
342
|
+
return () => clearInterval(timer)
|
|
343
|
+
}, [api, status, refreshStatusSilently])
|
|
344
|
+
|
|
345
|
+
if (!api) {
|
|
346
|
+
return h('div', { style: S.inner },
|
|
347
|
+
h('h2', { style: S.title }, 'GitHub 控制台'),
|
|
348
|
+
h('p', { style: S.error }, '面板桥未注入:刷新页面(Ctrl+R)。若仍然如此,插件 Host 未激活或 webServer 未就绪。'),
|
|
349
|
+
)
|
|
350
|
+
}
|
|
351
|
+
const loadRepos = () => run('repos', async () => {
|
|
352
|
+
const data = await api('repos', { q: repoQuery })
|
|
353
|
+
setRepos(data.items || [])
|
|
354
|
+
setReposTotal(data.total || 0)
|
|
355
|
+
setReposLoaded(true)
|
|
356
|
+
return data
|
|
357
|
+
})
|
|
358
|
+
|
|
359
|
+
const openRepo = (fullName) => {
|
|
360
|
+
const [owner, name] = String(fullName).split('/')
|
|
361
|
+
setSelectedRepo(fullName)
|
|
362
|
+
setFile(null)
|
|
363
|
+
setFileError('')
|
|
364
|
+
void run('tree', async () => {
|
|
365
|
+
const data = await api('tree', { owner, name })
|
|
366
|
+
setTree(data)
|
|
367
|
+
})
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
const openFile = (entryPath) => {
|
|
371
|
+
const [owner, name] = selectedRepo.split('/')
|
|
372
|
+
setFileError('')
|
|
373
|
+
setEditing(false)
|
|
374
|
+
setDraft('')
|
|
375
|
+
void run('file', async () => {
|
|
376
|
+
try {
|
|
377
|
+
const data = await api('file/read', { owner, name, path: entryPath })
|
|
378
|
+
setFile(data)
|
|
379
|
+
} catch (failure) {
|
|
380
|
+
setFileError(failure instanceof Error ? failure.message : String(failure))
|
|
381
|
+
}
|
|
382
|
+
})
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
// The sha read with the file is sent back, so a concurrent edit on GitHub
|
|
386
|
+
// fails with REF_CONFLICT instead of being overwritten.
|
|
387
|
+
const saveFile = () => {
|
|
388
|
+
if (!file) return
|
|
389
|
+
const [owner, name] = selectedRepo.split('/')
|
|
390
|
+
void run('save', async () => {
|
|
391
|
+
try {
|
|
392
|
+
const result = await api('file/write', {
|
|
393
|
+
owner,
|
|
394
|
+
name,
|
|
395
|
+
path: file.path,
|
|
396
|
+
text: draft,
|
|
397
|
+
sha: file.sha,
|
|
398
|
+
message: commitMessage || `chore: update ${file.path}`,
|
|
399
|
+
})
|
|
400
|
+
setEditing(false)
|
|
401
|
+
setCommitMessage('')
|
|
402
|
+
const fresh = await api('file/read', { owner, name, path: file.path })
|
|
403
|
+
setFile(fresh)
|
|
404
|
+
return result
|
|
405
|
+
} catch (failure) {
|
|
406
|
+
setFileError(failure instanceof Error ? failure.message : String(failure))
|
|
407
|
+
return undefined
|
|
408
|
+
}
|
|
409
|
+
})
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
const targetRepoFull = () => {
|
|
413
|
+
const owner = status && status.installation ? status.installation.account : ''
|
|
414
|
+
const repo = String(repoTarget).trim()
|
|
415
|
+
return owner && repo ? `${owner}/${repo}` : ''
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
const runDiscover = async (root) => {
|
|
419
|
+
setDiscoverError('')
|
|
420
|
+
const data = await runSilent(() => api('discover', { root: typeof root === 'string' ? root.trim() : '' }))
|
|
421
|
+
if (!data) {
|
|
422
|
+
setDiscoverError('扫描失败:Host 没有返回结果。换一个父目录再试,或直接在「发布」页填插件目录。')
|
|
423
|
+
return
|
|
424
|
+
}
|
|
425
|
+
setDiscovered(data)
|
|
426
|
+
// Keep the wizard pointing at something that exists after a rescan.
|
|
427
|
+
const first = data.items && data.items[0]
|
|
428
|
+
if (first) {
|
|
429
|
+
setPublishDir((current) => current || first.dir)
|
|
430
|
+
setRepoTarget((current) => (current || repoTargetEdited ? current : first.suggestedRepo))
|
|
431
|
+
setProbeName((current) => current || first.name)
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
const useCandidate = (item) => {
|
|
436
|
+
setPublishDir(item.dir)
|
|
437
|
+
// Choosing a directory re-derives the repository name unless the user
|
|
438
|
+
// typed one; otherwise plugin B's files could be pushed into A's repo.
|
|
439
|
+
if (!repoTargetEdited) setRepoTarget(item.suggestedRepo || item.name.replace(/^@[^/]+\//, ''))
|
|
440
|
+
setProbeName(item.name)
|
|
441
|
+
setReport(null)
|
|
442
|
+
setTab('publish')
|
|
443
|
+
void runPreflight(item.dir)
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
const loadInbox = () => {
|
|
447
|
+
const [owner, name] = String(selectedRepo || targetRepoFull()).split('/')
|
|
448
|
+
if (!owner || !name) {
|
|
449
|
+
setError('先选一个仓库')
|
|
450
|
+
return
|
|
451
|
+
}
|
|
452
|
+
void run('inbox', async () => {
|
|
453
|
+
// One missing permission must not blank the other two sections.
|
|
454
|
+
const settled = await Promise.allSettled([
|
|
455
|
+
api('issues', { owner, name, state: 'open' }),
|
|
456
|
+
api('pulls', { owner, name, state: 'open' }),
|
|
457
|
+
api('actions', { owner, name }),
|
|
458
|
+
])
|
|
459
|
+
const errors = settled
|
|
460
|
+
.map((item, index) => (item.status === 'rejected' ? `${['Issues', 'Pull requests', 'Actions'][index]}:${item.reason && item.reason.message ? item.reason.message : item.reason}` : ''))
|
|
461
|
+
.filter(Boolean)
|
|
462
|
+
setInbox({
|
|
463
|
+
issues: settled[0].status === 'fulfilled' ? settled[0].value : null,
|
|
464
|
+
pulls: settled[1].status === 'fulfilled' ? settled[1].value : null,
|
|
465
|
+
runs: settled[2].status === 'fulfilled' ? settled[2].value : null,
|
|
466
|
+
errors,
|
|
467
|
+
})
|
|
468
|
+
})
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
const repoRef = () => {
|
|
472
|
+
const [owner, name] = String(selectedRepo || targetRepoFull()).split('/')
|
|
473
|
+
if (!owner || !name) {
|
|
474
|
+
setError('先选一个仓库(仓库页或发布页填写 owner/repo)')
|
|
475
|
+
return null
|
|
476
|
+
}
|
|
477
|
+
return { owner, name }
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
const openPull = (number) => {
|
|
481
|
+
const ref = repoRef()
|
|
482
|
+
if (!ref) return
|
|
483
|
+
void run('pull', async () => {
|
|
484
|
+
const detail = await api('pull/detail', { ...ref, number })
|
|
485
|
+
setPullDetail(detail)
|
|
486
|
+
setCommentDraft('')
|
|
487
|
+
setReviewNote('')
|
|
488
|
+
})
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
const sendPullComment = (inline) => {
|
|
492
|
+
const ref = repoRef()
|
|
493
|
+
if (!ref || !pullDetail) return
|
|
494
|
+
const body = inline ? inlineTarget.trim() : commentDraft.trim()
|
|
495
|
+
if (!body) {
|
|
496
|
+
setError('评论内容不能为空')
|
|
497
|
+
return
|
|
498
|
+
}
|
|
499
|
+
void run('comment', async () => {
|
|
500
|
+
const payload = { ...ref, number: pullDetail.number, body }
|
|
501
|
+
if (inline) {
|
|
502
|
+
const [path, line] = inline.split('#')
|
|
503
|
+
payload.path = path
|
|
504
|
+
payload.line = Number(line)
|
|
505
|
+
}
|
|
506
|
+
await api('pull/comment', payload)
|
|
507
|
+
if (inline) setInlineTarget('')
|
|
508
|
+
else setCommentDraft('')
|
|
509
|
+
const detail = await api('pull/detail', { ...ref, number: pullDetail.number })
|
|
510
|
+
setPullDetail(detail)
|
|
511
|
+
})
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
const sendReview = (event) => {
|
|
515
|
+
const ref = repoRef()
|
|
516
|
+
if (!ref || !pullDetail) return
|
|
517
|
+
void run('review', async () => {
|
|
518
|
+
await api('pull/review', { ...ref, number: pullDetail.number, event, body: reviewNote.trim() })
|
|
519
|
+
setReviewNote('')
|
|
520
|
+
const detail = await api('pull/detail', { ...ref, number: pullDetail.number })
|
|
521
|
+
setPullDetail(detail)
|
|
522
|
+
})
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
const toggleIssue = (item) => {
|
|
526
|
+
const ref = repoRef()
|
|
527
|
+
if (!ref) return
|
|
528
|
+
void run('issue', async () => {
|
|
529
|
+
await api('issue/update', { ...ref, number: item.number, state: item.state === 'open' ? 'closed' : 'open' })
|
|
530
|
+
loadInbox()
|
|
531
|
+
})
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
const showLog = (runId) => {
|
|
535
|
+
const ref = repoRef()
|
|
536
|
+
if (!ref) return
|
|
537
|
+
void run('log', async () => {
|
|
538
|
+
setRunLog(await api('actions/log', { ...ref, runId, tailLines: 80 }))
|
|
539
|
+
})
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
const runPreflight = async (dirOverride) => { const dir = dirOverride || publishDir
|
|
543
|
+
if (!String(dir).trim()) {
|
|
544
|
+
setError('先选一个插件目录:可以在上方「本地发现」里点体检,或在这里填绝对路径')
|
|
545
|
+
return undefined
|
|
546
|
+
}
|
|
547
|
+
setPreflightingDir(dir)
|
|
548
|
+
const data = await run('preflight', () => api('publish/preflight', { dir }))
|
|
549
|
+
setPreflightingDir('')
|
|
550
|
+
if (!data) return undefined
|
|
551
|
+
setReport(data)
|
|
552
|
+
if (data.package) {
|
|
553
|
+
setProbeName((current) => current || data.package.name)
|
|
554
|
+
setProbeVersion((current) => current || data.package.version)
|
|
555
|
+
if (!repoTargetEdited) {
|
|
556
|
+
setRepoTarget(String(data.package.name || '').replace(/^@[^/]+\//, '').replace(/[^A-Za-z0-9._-]/g, '-'))
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
if (dirOverride) setPublishDir(dir)
|
|
560
|
+
return data
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
// The wizard asks three questions: which directory, which account, which
|
|
564
|
+
// repository name. Branch, message and notes live under 高级.
|
|
565
|
+
const startPublish = () => {
|
|
566
|
+
const owner = status && status.installation ? status.installation.account : ''
|
|
567
|
+
const repo = String(repoTarget).trim()
|
|
568
|
+
if (!String(publishDir).trim()) {
|
|
569
|
+
setError('还没有选插件目录:先在「本地发现」里点一个,或填写目录路径')
|
|
570
|
+
return
|
|
571
|
+
}
|
|
572
|
+
if (!owner) {
|
|
573
|
+
setError('还没有连接 GitHub 账号:先完成第 2 步')
|
|
574
|
+
return
|
|
575
|
+
}
|
|
576
|
+
if (!repo) {
|
|
577
|
+
setError('还需要一个仓库名(默认取 package.json 的名字)')
|
|
578
|
+
return
|
|
579
|
+
}
|
|
580
|
+
void run('publish', async () => {
|
|
581
|
+
const started = await api('publish/run', {
|
|
582
|
+
dir: publishDir,
|
|
583
|
+
owner,
|
|
584
|
+
repo,
|
|
585
|
+
branch: publishBranch.trim() || undefined,
|
|
586
|
+
notes: publishNotes.trim() || undefined,
|
|
587
|
+
})
|
|
588
|
+
setTab('publish')
|
|
589
|
+
for (let attempt = 0; attempt < 120; attempt++) {
|
|
590
|
+
const next = await api('publish/job', { jobId: started.jobId })
|
|
591
|
+
setJob(next)
|
|
592
|
+
if (next.preflight && next.preflight.package) {
|
|
593
|
+
setProbeName((current) => current || next.preflight.package.name)
|
|
594
|
+
setProbeVersion((current) => current || next.preflight.package.version)
|
|
595
|
+
}
|
|
596
|
+
if (next.finishedAt) return next
|
|
597
|
+
await new Promise((resolve) => setTimeout(resolve, 1000))
|
|
598
|
+
}
|
|
599
|
+
setError('发布轮询超过 120 秒仍未结束:任务仍在 Host 侧运行,可稍后重新发布同一版本(已完成步骤会跳过)')
|
|
600
|
+
return undefined
|
|
601
|
+
})
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
const targetOwner = status && status.installation ? status.installation.account : ''
|
|
605
|
+
const createRepoUrl = targetOwner
|
|
606
|
+
? targetOwner === (status && status.app && status.app.owner)
|
|
607
|
+
? `https://github.com/new?name=${encodeURIComponent(repoTarget || 'my-plugin')}&visibility=private&description=${encodeURIComponent('DSH plugin')}`
|
|
608
|
+
: `https://github.com/organizations/${encodeURIComponent(targetOwner)}/repositories/new?name=${encodeURIComponent(repoTarget || 'my-plugin')}&visibility=private&description=${encodeURIComponent('DSH plugin')}`
|
|
609
|
+
: ''
|
|
610
|
+
|
|
611
|
+
// npm publishing runs in GitHub Actions: the workflow file is the only
|
|
612
|
+
// thing written to the repo, and the token/IPC never leaves the runner.
|
|
613
|
+
const runNpmPublish = () => {
|
|
614
|
+
const owner = targetOwner
|
|
615
|
+
const repo = String(repoTarget).trim()
|
|
616
|
+
if (!owner || !repo) {
|
|
617
|
+
setError('先完成第 2 步并填好仓库名')
|
|
618
|
+
return
|
|
619
|
+
}
|
|
620
|
+
void run('npm', async () => {
|
|
621
|
+
const prepared = await api('npm/prepare', { dir: publishDir, owner, repo })
|
|
622
|
+
const ok =
|
|
623
|
+
typeof window === 'undefined' ||
|
|
624
|
+
window.confirm(`会在 ${owner}/${repo} 里写入 ${prepared.path},然后触发一次 npm 发布(${prepared.package})。继续?`)
|
|
625
|
+
if (!ok) return prepared
|
|
626
|
+
const dispatched = await api('npm/dispatch', { owner, repo })
|
|
627
|
+
setNpmRun(dispatched.run)
|
|
628
|
+
return dispatched
|
|
629
|
+
})
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
const loadNpmState = () => {
|
|
633
|
+
const owner = targetOwner
|
|
634
|
+
const repo = String(repoTarget).trim()
|
|
635
|
+
if (!owner || !repo) {
|
|
636
|
+
setError('先完成第 2 步并填好仓库名')
|
|
637
|
+
return
|
|
638
|
+
}
|
|
639
|
+
void run('npmstate', async () => {
|
|
640
|
+
const state = await api('npm/status', { dir: publishDir, owner, repo })
|
|
641
|
+
setNpmState(state)
|
|
642
|
+
return state
|
|
643
|
+
})
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
const attachMarket = () => {
|
|
647
|
+
void run('attach', async () => {
|
|
648
|
+
const result = await api('market/attach', {})
|
|
649
|
+
setMarketAttach(result)
|
|
650
|
+
return result
|
|
651
|
+
})
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
const checkReadiness = () => {
|
|
655
|
+
const owner = targetOwner
|
|
656
|
+
const repo = String(repoTarget).trim()
|
|
657
|
+
if (!owner || !repo) {
|
|
658
|
+
setError('先完成第 2 步并填好仓库名')
|
|
659
|
+
return
|
|
660
|
+
}
|
|
661
|
+
void run('readiness', async () => {
|
|
662
|
+
const result = await api('market/readiness', { dir: publishDir, owner, repo })
|
|
663
|
+
setReadiness(result)
|
|
664
|
+
return result
|
|
665
|
+
})
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
const makeReleaseAsset = () => { const owner = targetOwner
|
|
669
|
+
const repo = String(repoTarget).trim()
|
|
670
|
+
if (!owner || !repo) {
|
|
671
|
+
setError('先完成第 2 步并填好仓库名')
|
|
672
|
+
return
|
|
673
|
+
}
|
|
674
|
+
void run('asset', async () => {
|
|
675
|
+
const result = await api('release/asset', { dir: publishDir, owner, repo })
|
|
676
|
+
setReleaseAsset(result)
|
|
677
|
+
return result
|
|
678
|
+
})
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
const makeMarketIndex = () => { const owner = targetOwner
|
|
682
|
+
const repo = String(repoTarget).trim()
|
|
683
|
+
if (!owner || !repo) {
|
|
684
|
+
setError('先完成第 2 步并填好仓库名')
|
|
685
|
+
return
|
|
686
|
+
}
|
|
687
|
+
void run('index', async () => {
|
|
688
|
+
const data = await api('market/index', { dir: publishDir, owner, repo })
|
|
689
|
+
setMarketIndex(data)
|
|
690
|
+
return data
|
|
691
|
+
})
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
const runProbe = () => { const [owner, repo] = targetRepoFull().split('/')
|
|
695
|
+
if (!probeName.trim()) {
|
|
696
|
+
setError('先填包名(package.json 的 name)')
|
|
697
|
+
return
|
|
698
|
+
}
|
|
699
|
+
void run('probe', async () => {
|
|
700
|
+
const data = await api('market/probe', {
|
|
701
|
+
name: probeName.trim(),
|
|
702
|
+
owner,
|
|
703
|
+
repo,
|
|
704
|
+
version: probeVersion.trim(),
|
|
705
|
+
})
|
|
706
|
+
setProbe(data)
|
|
707
|
+
return data
|
|
708
|
+
})
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
// An existing App must never be re-registered by accident: that replaces
|
|
712
|
+
// the private key and drops the chosen installation. Only the status page
|
|
713
|
+
// offers 重新注册, and it passes reset after a confirmation.
|
|
714
|
+
const registerApp = (reset) => run('register', async () => {
|
|
715
|
+
const data = await api('auth/register', reset === true ? { reset: true } : {})
|
|
716
|
+
setSetupUrl(data.setupUrl)
|
|
717
|
+
// Popups are often blocked in the desktop window; the visible link below
|
|
718
|
+
// the header stays available either way.
|
|
719
|
+
try {
|
|
720
|
+
window.open(data.setupUrl, '_blank', 'noreferrer')
|
|
721
|
+
} catch {
|
|
722
|
+
/* the visible link is the fallback */
|
|
723
|
+
}
|
|
724
|
+
return data
|
|
725
|
+
})
|
|
726
|
+
|
|
727
|
+
const useConnection = async (kind) => {
|
|
728
|
+
setAuthBusy(kind)
|
|
729
|
+
setAuthMessage('')
|
|
730
|
+
try {
|
|
731
|
+
await api('auth/use', { kind })
|
|
732
|
+
await refreshStatus()
|
|
733
|
+
setAuthMessage(`已切换到 ${kind}`)
|
|
734
|
+
} catch (failure) {
|
|
735
|
+
setAuthMessage(failure instanceof Error ? failure.message : String(failure))
|
|
736
|
+
} finally {
|
|
737
|
+
setAuthBusy('')
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
const savePat = async () => {
|
|
742
|
+
if (!patInput.trim()) {
|
|
743
|
+
setAuthMessage('先粘贴一个令牌')
|
|
744
|
+
return
|
|
745
|
+
}
|
|
746
|
+
setAuthBusy('pat')
|
|
747
|
+
setAuthMessage('')
|
|
748
|
+
try {
|
|
749
|
+
const result = await api('auth/pat', { token: patInput.trim() })
|
|
750
|
+
setPatInput('')
|
|
751
|
+
setAuthMessage(`已保存令牌(${result.login || '未知账号'} · ${result.fingerprint}),并设为当前连接`)
|
|
752
|
+
await refreshStatus()
|
|
753
|
+
} catch (failure) {
|
|
754
|
+
setAuthMessage(failure instanceof Error ? failure.message : String(failure))
|
|
755
|
+
} finally {
|
|
756
|
+
setAuthBusy('')
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
|
|
760
|
+
const clearPat = async () => {
|
|
761
|
+
setAuthBusy('pat-clear')
|
|
762
|
+
setAuthMessage('')
|
|
763
|
+
try {
|
|
764
|
+
await api('auth/pat/clear', {})
|
|
765
|
+
setAuthMessage('已删除本机保存的令牌')
|
|
766
|
+
await refreshStatus()
|
|
767
|
+
} catch (failure) {
|
|
768
|
+
setAuthMessage(failure instanceof Error ? failure.message : String(failure))
|
|
769
|
+
} finally {
|
|
770
|
+
setAuthBusy('')
|
|
771
|
+
}
|
|
772
|
+
}
|
|
773
|
+
|
|
774
|
+
// Device flow needs no callback URL, so it is independent of the web port.
|
|
775
|
+
const startDevice = async () => {
|
|
776
|
+
setAuthBusy('device')
|
|
777
|
+
setAuthMessage('')
|
|
778
|
+
try {
|
|
779
|
+
const started = await api('auth/device/start', {})
|
|
780
|
+
setDevice(started)
|
|
781
|
+
setAuthMessage(`在 ${started.verificationUri} 输入 ${started.userCode}(${Math.round(started.expiresIn / 60)} 分钟内有效)`)
|
|
782
|
+
const poll = async () => {
|
|
783
|
+
try {
|
|
784
|
+
const result = await api('auth/device/poll', { deviceCode: started.deviceCode })
|
|
785
|
+
if (result.status === 'ok') {
|
|
786
|
+
setDevice(null)
|
|
787
|
+
setAuthMessage('授权完成,已切换为「App 用户授权」:通知与代码搜索现在可用')
|
|
788
|
+
await refreshStatus()
|
|
789
|
+
return
|
|
790
|
+
}
|
|
791
|
+
if (result.status === 'expired' || result.status === 'denied') {
|
|
792
|
+
setDevice(null)
|
|
793
|
+
setAuthMessage(result.status === 'expired' ? '设备码已过期,请重新发起' : '授权被拒绝')
|
|
794
|
+
return
|
|
795
|
+
}
|
|
796
|
+
setTimeout(() => { void poll() }, result.slowDown ? 8000 : 5000)
|
|
797
|
+
} catch (failure) {
|
|
798
|
+
setDevice(null)
|
|
799
|
+
setAuthMessage(failure instanceof Error ? failure.message : String(failure))
|
|
800
|
+
}
|
|
801
|
+
}
|
|
802
|
+
setTimeout(() => { void poll() }, 5000)
|
|
803
|
+
} catch (failure) {
|
|
804
|
+
setAuthMessage(failure instanceof Error ? failure.message : String(failure))
|
|
805
|
+
} finally {
|
|
806
|
+
setAuthBusy('')
|
|
807
|
+
}
|
|
808
|
+
}
|
|
809
|
+
|
|
810
|
+
const installUrl = status && status.app && status.app.slug ? `https://github.com/apps/${status.app.slug}/installations/new`
|
|
811
|
+
: 'https://github.com/settings/installations'
|
|
812
|
+
|
|
813
|
+
// The saved installation may be gone (uninstalled on GitHub): compare it
|
|
814
|
+
// with the live list instead of trusting the local record.
|
|
815
|
+
const liveIds = Array.isArray(status && status.installations)
|
|
816
|
+
? status.installations.map((item) => String(item.id))
|
|
817
|
+
: []
|
|
818
|
+
const installationStale = Boolean(
|
|
819
|
+
status && status.installation && liveIds.length > 0 && !liveIds.includes(String(status.installation.id)),
|
|
820
|
+
)
|
|
821
|
+
|
|
822
|
+
const authKind = status && status.auth ? status.auth.kind : 'none'
|
|
823
|
+
const authAccount = status && status.auth ? status.auth.account : ''
|
|
824
|
+
|
|
825
|
+
const badge = status && status.configured
|
|
826
|
+
? status.installation ? `已连接 ${status.installation.account}` : 'App 已注册,尚未安装'
|
|
827
|
+
: '未配置'
|
|
828
|
+
|
|
829
|
+
return h('div', { style: S.inner },
|
|
830
|
+
h('div', { style: S.header },
|
|
831
|
+
h('div', null,
|
|
832
|
+
h('h2', { style: S.title }, 'GitHub 控制台'),
|
|
833
|
+
h('div', { style: S.sub }, `v${status ? status.version : '0.1.0'} · ${badge}${status && status.repositoryCount !== null && status.repositoryCount !== undefined ? ` · ${status.repositoryCount} 个仓库` : ''}`),
|
|
834
|
+
),
|
|
835
|
+
h('span', { style: S.badge(Boolean(status && status.installation)) }, busy ? '处理中…' : status && status.installation ? '已连接' : '未就绪'),
|
|
836
|
+
),
|
|
837
|
+
error ? h('div', { style: S.error }, error) : null,
|
|
838
|
+
installationStale
|
|
839
|
+
? h('div', { style: S.warn },
|
|
840
|
+
`本地记录的安装(id ${status.installation.id})在 App 的安装列表里已经找不到了:可能已在 GitHub 上取消。`,
|
|
841
|
+
h('button', { style: { ...S.button, marginLeft: 8, padding: '2px 10px', fontSize: 12 }, onClick: () => run('resetInstall', async () => { await api('auth/reset'); await refreshStatus() }) }, '清除本地凭据'),
|
|
842
|
+
)
|
|
843
|
+
: null,
|
|
844
|
+
// A blocked popup must never be a dead end: this link works everywhere.
|
|
845
|
+
setupUrl
|
|
846
|
+
? h('div', { style: { ...S.card, borderColor: 'var(--dsw-alias-border-l2)' } },
|
|
847
|
+
h('strong', { style: { fontSize: 13 } }, '新窗口没打开?手动继续'),
|
|
848
|
+
h('p', { style: S.notice }, '复制或点下面的地址打开 GitHub 创建页;完成后回到这里,状态会自动更新。'),
|
|
849
|
+
h('a', { href: setupUrl, target: '_blank', rel: 'noreferrer', style: { color: 'var(--dsw-alias-brand-primary)', fontSize: 12, overflowWrap: 'anywhere' } }, setupUrl),
|
|
850
|
+
)
|
|
851
|
+
: null,
|
|
852
|
+
// First-run card: local discovery and an offline report work with no
|
|
853
|
+
// GitHub account at all, so the first thing a new user sees is value.
|
|
854
|
+
h('div', { style: { ...S.card, borderColor: 'var(--dsw-alias-border-l2)' } },
|
|
855
|
+
h('div', { style: { ...S.line, justifyContent: 'space-between' } },
|
|
856
|
+
h('strong', { style: { fontSize: 13 } },
|
|
857
|
+
discovered && discovered.count
|
|
858
|
+
? `发现 ${discovered.count} 个可以发布的插件`
|
|
859
|
+
: '先看本地:哪些目录可以发布'),
|
|
860
|
+
h('div', { style: { display: 'flex', gap: 6 } },
|
|
861
|
+
h('button', { style: S.button, disabled: busy === 'discover', onClick: () => runDiscover(discoverRoot) }, busy === 'discover' ? '扫描中…' : '重新扫描'),
|
|
862
|
+
),
|
|
863
|
+
),
|
|
864
|
+
discovered === null && !discoverError
|
|
865
|
+
? h('p', { style: S.notice }, '正在扫描工作区…')
|
|
866
|
+
: null,
|
|
867
|
+
discoverError
|
|
868
|
+
? h('div', null,
|
|
869
|
+
h('div', { style: S.warn }, discoverError),
|
|
870
|
+
h('div', { style: { display: 'flex', gap: 8, marginTop: 6 } },
|
|
871
|
+
h('input', { style: S.input, value: discoverRoot, placeholder: '换一个父目录再试,例如 C:\\Users\\你\\projects', onChange: (event) => setDiscoverRoot(event.target.value), onKeyDown: (event) => { if (event.key === 'Enter') void runDiscover(discoverRoot) } }),
|
|
872
|
+
h('button', { style: S.button, onClick: () => runDiscover(discoverRoot) }, '扫描'),
|
|
873
|
+
),
|
|
874
|
+
)
|
|
875
|
+
: null,
|
|
876
|
+
discovered && discovered.count === 0
|
|
877
|
+
? h('div', null,
|
|
878
|
+
h('p', { style: S.notice }, '没找到声明 dsh.bundle.patch 的插件目录(只扫项目根及其下两级)。填一个父目录再扫一次:'),
|
|
879
|
+
h('div', { style: { display: 'flex', gap: 8, marginTop: 6 } },
|
|
880
|
+
h('input', { style: S.input, value: discoverRoot, placeholder: '例如 C:\\Users\\你\\projects', onChange: (event) => setDiscoverRoot(event.target.value), onKeyDown: (event) => { if (event.key === 'Enter') void runDiscover(discoverRoot) } }),
|
|
881
|
+
h('button', { style: S.button, disabled: busy === 'discover', onClick: () => runDiscover(discoverRoot) }, '扫描'),
|
|
882
|
+
),
|
|
883
|
+
)
|
|
884
|
+
: null,
|
|
885
|
+
(discovered ? discovered.items : []).slice(0, 8).map((item) =>
|
|
886
|
+
h('div', { key: item.dir, style: S.row },
|
|
887
|
+
h('span', { style: S.name, title: item.dir }, item.name || item.dir),
|
|
888
|
+
h('span', { style: S.meta }, item.version || ''),
|
|
889
|
+
h('button', { style: S.button, disabled: Boolean(preflightingDir), onClick: () => useCandidate(item) }, preflightingDir === item.dir ? '体检中…' : '体检'),
|
|
890
|
+
),
|
|
891
|
+
),
|
|
892
|
+
discovered && discovered.count > 8
|
|
893
|
+
? h('p', { style: S.notice }, `只列出最近修改的 8 个(共 ${discovered.count} 个${discovered.limited ? ',已达到 40 条扫描上限' : ''});其余可在「发布」页直接填目录。`)
|
|
894
|
+
: null,
|
|
895
|
+
discovered && discovered.roots && discovered.roots.length
|
|
896
|
+
? h('p', { style: S.notice }, '已扫描:', discovered.roots.map((item) => `${item.root}${item.exists ? `(${item.found})` : '(不存在)'}`).join(' · '))
|
|
897
|
+
: null,
|
|
898
|
+
h('p', { style: S.notice }, '扫描只读本地文件;体检会把包名发到 npm registry 查重,除此之外不上传任何内容,也不需要 GitHub 账号。'),
|
|
899
|
+
),
|
|
900
|
+
h('div', { style: S.tabs, role: 'tablist' },
|
|
901
|
+
['status', 'repos', 'inbox', 'publish', 'market'].map((key) =>
|
|
902
|
+
h(Tab, { key, active: tab === key, onClick: () => { setTab(key); if (key === 'repos' && !reposLoaded) loadRepos() } },
|
|
903
|
+
{ status: '状态', repos: '仓库', inbox: '收件箱', publish: '发布', market: '市场' }[key]),
|
|
904
|
+
),
|
|
905
|
+
),
|
|
906
|
+
|
|
907
|
+
tab === 'status'
|
|
908
|
+
? h('div', null,
|
|
909
|
+
h('div', { style: S.card },
|
|
910
|
+
h('div', { style: S.line }, h('span', { style: S.label }, 'GitHub App'), h('span', { style: S.value }, status && status.app ? `${status.app.name || '未命名'} · ID ${status.app.appId}` : '尚未注册')),
|
|
911
|
+
h('div', { style: S.line }, h('span', { style: S.label }, '安装'), h('span', { style: S.value }, status && status.installation ? `${status.installation.account} (id ${status.installation.id})` : status && status.app ? 'App 已就绪,但还没安装到任何账号' : '尚未注册')),
|
|
912
|
+
status && status.app
|
|
913
|
+
? h('div', { style: S.line }, h('span', { style: S.label }, '令牌'), h('span', { style: S.value }, status.installationToken ? `有效至 ${new Date(status.installationToken.expiresAt).toLocaleTimeString()}` : '尚未换取(首次调用时自动获取)'))
|
|
914
|
+
: null,
|
|
915
|
+
h('div', { style: S.line }, h('span', { style: S.label }, '发布默认'), h('span', { style: S.value }, status && status.publish ? `分支 ${status.publish.branch} · topic ${status.publish.topic}` : '')),
|
|
916
|
+
status && status.error ? h('div', { style: S.warn }, status.error) : null,
|
|
917
|
+
status && status.errors && status.errors.length
|
|
918
|
+
? status.errors.map((item, index) => h('div', { key: index, style: S.warn }, item))
|
|
919
|
+
: null,
|
|
920
|
+
status && status.network && status.network.hint
|
|
921
|
+
? h('div', { style: S.warn }, status.network.hint)
|
|
922
|
+
: null,
|
|
923
|
+
),
|
|
924
|
+
h('div', { style: S.card },
|
|
925
|
+
h('div', { style: { ...S.line, justifyContent: 'space-between' } },
|
|
926
|
+
h('strong', { style: { fontSize: 13 } }, '连接方式'),
|
|
927
|
+
h('span', { style: S.badge(authKind === 'app' || authKind === 'pat' || authKind === 'env') },
|
|
928
|
+
{ app: 'GitHub App', pat: '个人访问令牌', env: '环境变量', none: '未连接' }[authKind] || authKind),
|
|
929
|
+
),
|
|
930
|
+
h('p', { style: S.notice }, `当前账号:${authAccount || '—'}${status && status.auth && status.auth.readOnly ? ' · 只读模式' : ''}`),
|
|
931
|
+
h('div', { style: { display: 'flex', gap: 6, flexWrap: 'wrap', margin: '6px 0' } },
|
|
932
|
+
[['app', 'GitHub App'], ['oauth', 'App 用户授权'], ['pat', '个人访问令牌'], ['env', `环境变量(${status && status.connections ? status.connections.env.name : 'GITHUB_TOKEN'})`]].map(([kind, label]) =>
|
|
933
|
+
h('button', {
|
|
934
|
+
key: kind,
|
|
935
|
+
style: authKind === kind ? { ...S.primary, padding: '4px 12px', fontSize: 12 } : { ...S.button, padding: '4px 12px', fontSize: 12 },
|
|
936
|
+
disabled: authBusy === kind,
|
|
937
|
+
onClick: () => useConnection(kind),
|
|
938
|
+
}, label),
|
|
939
|
+
),
|
|
940
|
+
),
|
|
941
|
+
h('div', { style: { display: 'flex', gap: 6, marginTop: 4, flexWrap: 'wrap' } },
|
|
942
|
+
h('input', {
|
|
943
|
+
style: { ...S.input, flex: 1, minWidth: 200 },
|
|
944
|
+
type: 'password',
|
|
945
|
+
value: patInput,
|
|
946
|
+
placeholder: status && status.connections && status.connections.pat.configured ? `已保存 ${status.connections.pat.fingerprint}(粘贴新值可替换)` : '粘贴个人访问令牌(ghp_… / github_pat_…)',
|
|
947
|
+
onChange: (event) => setPatInput(event.target.value),
|
|
948
|
+
}),
|
|
949
|
+
h('button', { style: S.button, disabled: authBusy === 'pat', onClick: savePat }, authBusy === 'pat' ? '验证中…' : '保存令牌'),
|
|
950
|
+
status && status.connections && status.connections.pat.configured
|
|
951
|
+
? h('button', { style: S.danger, disabled: authBusy === 'pat-clear', onClick: clearPat }, '删除令牌')
|
|
952
|
+
: null,
|
|
953
|
+
),
|
|
954
|
+
h('p', { style: S.notice }, '令牌只写入 DSH 凭据服务,面板只显示末四位;环境变量方式不落盘。通知中心与代码搜索只有用户令牌能做,App 安装令牌做不到。'),
|
|
955
|
+
h('div', { style: { display: 'flex', gap: 8, flexWrap: 'wrap', marginTop: 4 } },
|
|
956
|
+
h('button', {
|
|
957
|
+
style: S.primary,
|
|
958
|
+
disabled: authBusy === 'device' || Boolean(device),
|
|
959
|
+
onClick: startDevice,
|
|
960
|
+
}, authBusy === 'device' ? '申请中…' : device ? `等待授权:${device.userCode}` : '设备码授权(推荐,无需回调地址)'),
|
|
961
|
+
h('button', {
|
|
962
|
+
style: S.button,
|
|
963
|
+
disabled: authBusy === 'oauth',
|
|
964
|
+
onClick: async () => {
|
|
965
|
+
setAuthBusy('oauth')
|
|
966
|
+
setAuthMessage('')
|
|
967
|
+
try {
|
|
968
|
+
const result = await api('auth/oauth/start', {})
|
|
969
|
+
window.open(result.url, '_blank', 'noreferrer')
|
|
970
|
+
setAuthMessage(
|
|
971
|
+
result.callbackRegistered
|
|
972
|
+
? '已打开 GitHub 授权页:同意后回来点「刷新状态」,再选「App 用户授权」。'
|
|
973
|
+
: `先在 App 设置里加这个回调地址再授权:${result.callbackUrl}`,
|
|
974
|
+
)
|
|
975
|
+
} catch (failure) {
|
|
976
|
+
setAuthMessage(failure instanceof Error ? failure.message : String(failure))
|
|
977
|
+
} finally {
|
|
978
|
+
setAuthBusy('')
|
|
979
|
+
}
|
|
980
|
+
},
|
|
981
|
+
}, authBusy === 'oauth' ? '打开中…' : '授权 App 用户身份(拿通知与代码搜索)'),
|
|
982
|
+
status && status.connections && status.connections.oauth && status.connections.oauth.configured
|
|
983
|
+
? h('button', {
|
|
984
|
+
style: S.danger,
|
|
985
|
+
onClick: async () => {
|
|
986
|
+
await api('auth/oauth/clear', {})
|
|
987
|
+
setAuthMessage('已删除用户授权')
|
|
988
|
+
await refreshStatus()
|
|
989
|
+
},
|
|
990
|
+
}, '撤销用户授权')
|
|
991
|
+
: null,
|
|
992
|
+
),
|
|
993
|
+
authMessage ? h('p', { style: S.notice }, authMessage) : null,
|
|
994
|
+
device
|
|
995
|
+
? h('p', { style: S.notice },
|
|
996
|
+
'在浏览器打开 ',
|
|
997
|
+
h('a', { href: device.verificationUri, target: '_blank', rel: 'noreferrer', style: { color: 'var(--dsw-alias-brand-primary)' } }, device.verificationUri),
|
|
998
|
+
',输入 ',
|
|
999
|
+
h(CopyValue, { value: device.userCode }),
|
|
1000
|
+
' 并确认。插件会自动轮询结果。',
|
|
1001
|
+
)
|
|
1002
|
+
: null,
|
|
1003
|
+
status && status.auth && status.auth.capabilities
|
|
1004
|
+
? h('div', { style: { marginTop: 6 } },
|
|
1005
|
+
h('div', { style: S.meta }, '当前连接的能力'),
|
|
1006
|
+
h('div', { style: { display: 'flex', gap: 10, flexWrap: 'wrap', marginTop: 4, fontSize: 12 } },
|
|
1007
|
+
[
|
|
1008
|
+
['repoRead', '代码读'],
|
|
1009
|
+
['repoWrite', '代码写'],
|
|
1010
|
+
['pullWrite', 'PR 写'],
|
|
1011
|
+
['issueWrite', 'Issue 写'],
|
|
1012
|
+
['actionsWrite', 'Actions'],
|
|
1013
|
+
['workflowsWrite', 'Workflow'],
|
|
1014
|
+
['adminWrite', '管理'],
|
|
1015
|
+
['notifications', '通知'],
|
|
1016
|
+
['codeSearch', '代码搜索'],
|
|
1017
|
+
].map(([key, label]) =>
|
|
1018
|
+
h('span', { key, style: { color: status.auth.capabilities[key] ? 'var(--dsw-alias-state-success-primary)' : 'var(--dsw-alias-label-secondary)' } },
|
|
1019
|
+
`${status.auth.capabilities[key] ? '✓' : '✕'} ${label}`),
|
|
1020
|
+
),
|
|
1021
|
+
),
|
|
1022
|
+
)
|
|
1023
|
+
: null,
|
|
1024
|
+
status && status.auth && status.auth.readOnly
|
|
1025
|
+
? h('p', { style: S.warn }, `只读:${status.auth.readOnlyReason || '当前连接没有写权限'}`)
|
|
1026
|
+
: null,
|
|
1027
|
+
),
|
|
1028
|
+
// Next-step card: exactly one primary action per state, so a user who
|
|
1029
|
+
// just registered is never told to register again.
|
|
1030
|
+
h('div', { style: S.card },
|
|
1031
|
+
h('strong', { style: { fontSize: 13 } }, !status || !status.configured
|
|
1032
|
+
? '第 1 步:注册一个仅你可见的 GitHub App'
|
|
1033
|
+
: !status.installation
|
|
1034
|
+
? '第 2 步:把 App 安装到你的账号或组织'
|
|
1035
|
+
: '已就绪:可以浏览仓库与发布插件'),
|
|
1036
|
+
h('p', { style: S.notice }, !status || !status.configured
|
|
1037
|
+
? '点击后会在你的 GitHub 账号下创建一个私有 App(权限:仓库内容读写 / 管理 / PR / Issue / Actions / Workflows)。私钥只写入 DSH 凭据服务,面板永远拿不到原文。'
|
|
1038
|
+
: !status.installation
|
|
1039
|
+
? '安装时选择要交给插件的仓库(可选全部或指定仓库)。装完通常几秒后自动更新;没反应再点「刷新状态」。'
|
|
1040
|
+
: '仓库页可以浏览文件并直接提交修改;发布页可以体检并推送到已存在的仓库。'),
|
|
1041
|
+
h('div', { style: { display: 'flex', gap: 8, marginTop: 12, flexWrap: 'wrap', alignItems: 'center' } },
|
|
1042
|
+
!status || !status.configured
|
|
1043
|
+
? h('button', { style: S.primary, disabled: busy === 'register', onClick: () => registerApp(false) }, busy === 'register' ? '准备中…' : '注册 GitHub App')
|
|
1044
|
+
: !status.installation
|
|
1045
|
+
? h('a', { href: installUrl, target: '_blank', rel: 'noreferrer', style: { ...S.primary, display: 'inline-block', textDecoration: 'none' } }, '打开 App 安装页')
|
|
1046
|
+
: null,
|
|
1047
|
+
h('button', { style: S.button, disabled: busy === 'status', onClick: refreshStatus }, busy === 'status' ? '刷新中…' : '刷新状态'),
|
|
1048
|
+
status && status.configured
|
|
1049
|
+
? h('button', {
|
|
1050
|
+
style: S.danger,
|
|
1051
|
+
disabled: busy === 'register',
|
|
1052
|
+
onClick: () => {
|
|
1053
|
+
const ok = typeof window === 'undefined' || window.confirm('重新注册会替换本机保存的 App 私钥,并清掉已选安装。确定继续?')
|
|
1054
|
+
if (!ok) return
|
|
1055
|
+
void registerApp(true)
|
|
1056
|
+
},
|
|
1057
|
+
}, '重新注册 GitHub App')
|
|
1058
|
+
: null,
|
|
1059
|
+
status && status.configured
|
|
1060
|
+
? h('button', {
|
|
1061
|
+
style: S.danger,
|
|
1062
|
+
disabled: busy === 'reset',
|
|
1063
|
+
onClick: () => {
|
|
1064
|
+
const ok = typeof window === 'undefined' || window.confirm('清除本机保存的 GitHub App 凭据?私钥本机只有这一份,清除后需要重新注册 App。')
|
|
1065
|
+
if (!ok) return
|
|
1066
|
+
void run('reset', async () => {
|
|
1067
|
+
await api('auth/reset')
|
|
1068
|
+
setSetupUrl('')
|
|
1069
|
+
await refreshStatus()
|
|
1070
|
+
})
|
|
1071
|
+
},
|
|
1072
|
+
}, '清除本地 App 凭据')
|
|
1073
|
+
: null,
|
|
1074
|
+
),
|
|
1075
|
+
setupUrl
|
|
1076
|
+
? h('p', { style: S.notice },
|
|
1077
|
+
'若新窗口没有自动打开,手动打开:',
|
|
1078
|
+
h('br'),
|
|
1079
|
+
h('a', { href: setupUrl, target: '_blank', rel: 'noreferrer', style: { color: 'var(--dsw-alias-brand-primary)', overflowWrap: 'anywhere' } }, setupUrl),
|
|
1080
|
+
)
|
|
1081
|
+
: null,
|
|
1082
|
+
),
|
|
1083
|
+
status && status.installations && status.installations.length
|
|
1084
|
+
? h('div', { style: S.card },
|
|
1085
|
+
h('strong', { style: { fontSize: 13 } }, '选择 installation'),
|
|
1086
|
+
status.installations.map((item) =>
|
|
1087
|
+
h('div', { key: item.id, style: S.row },
|
|
1088
|
+
h('span', { style: S.name }, `${item.account}${item.accountType ? ` · ${item.accountType}` : ''}`),
|
|
1089
|
+
h('span', { style: S.meta }, `id ${item.id}`),
|
|
1090
|
+
status.installation && String(status.installation.id) === String(item.id)
|
|
1091
|
+
? h('span', { style: S.badge(true) }, '当前')
|
|
1092
|
+
: h('button', { style: S.button, disabled: busy === 'select', onClick: () => run('select', async () => { await api('installations/select', { id: item.id }); await refreshStatus() }) }, '使用'),
|
|
1093
|
+
),
|
|
1094
|
+
),
|
|
1095
|
+
)
|
|
1096
|
+
: null,
|
|
1097
|
+
)
|
|
1098
|
+
: null,
|
|
1099
|
+
|
|
1100
|
+
tab === 'repos'
|
|
1101
|
+
? h('div', null,
|
|
1102
|
+
h('div', { style: { display: 'flex', gap: 8, marginBottom: 10 } },
|
|
1103
|
+
h('input', { style: S.input, value: repoQuery, placeholder: '按 owner/name 过滤', onChange: (event) => setRepoQuery(event.target.value), onKeyDown: (event) => { if (event.key === 'Enter') void loadRepos() } }),
|
|
1104
|
+
h('button', { style: S.button, disabled: busy === 'repos', onClick: loadRepos }, busy === 'repos' ? '查询中…' : '查询'),
|
|
1105
|
+
),
|
|
1106
|
+
!reposLoaded
|
|
1107
|
+
? h('p', { style: S.notice }, '点「查询」列出 App 安装范围内的仓库。')
|
|
1108
|
+
: repos.length === 0
|
|
1109
|
+
? h('p', { style: S.notice }, reposTotal > 0 ? '没有匹配的仓库,换个过滤词试试。' : 'App 的安装范围内还没有仓库:到 GitHub → Settings → Applications 里给这个安装添加仓库。')
|
|
1110
|
+
: h('div', { style: S.card },
|
|
1111
|
+
h('div', { style: { ...S.line, justifyContent: 'space-between' } },
|
|
1112
|
+
h('span', { style: S.meta }, `共 ${reposTotal} 个,显示 ${repos.length} 个`),
|
|
1113
|
+
),
|
|
1114
|
+
repos.map((repo) =>
|
|
1115
|
+
h('div', { key: repo.id, style: { ...S.row, cursor: 'pointer', background: selectedRepo === repo.fullName ? 'var(--dsw-alias-bg-layer-2)' : 'transparent' }, onClick: () => openRepo(repo.fullName) },
|
|
1116
|
+
h('span', { style: S.name }, repo.fullName),
|
|
1117
|
+
h('span', { style: S.meta }, repo.private ? '私有' : '公开'),
|
|
1118
|
+
h('span', { style: S.meta }, repo.defaultBranch),
|
|
1119
|
+
),
|
|
1120
|
+
),
|
|
1121
|
+
),
|
|
1122
|
+
tree
|
|
1123
|
+
? h('div', { style: S.card },
|
|
1124
|
+
h('div', { style: { ...S.line, justifyContent: 'space-between' } },
|
|
1125
|
+
h('strong', { style: { fontSize: 13 } }, `${selectedRepo} @ ${tree.ref}`),
|
|
1126
|
+
h('span', { style: S.meta }, `${tree.returned} 项${tree.truncated ? '(已截断)' : ''}`),
|
|
1127
|
+
),
|
|
1128
|
+
h('div', { style: { maxHeight: 260, overflowY: 'auto' } },
|
|
1129
|
+
tree.entries.filter((entry) => entry.type === 'blob').slice(0, 200).map((entry) =>
|
|
1130
|
+
h('div', { key: entry.sha + entry.path, style: { ...S.row, cursor: 'pointer' }, onClick: () => openFile(entry.path) },
|
|
1131
|
+
h('span', { style: S.name }, entry.path),
|
|
1132
|
+
h('span', { style: S.meta }, entry.size === null ? '' : `${entry.size} B`),
|
|
1133
|
+
),
|
|
1134
|
+
),
|
|
1135
|
+
),
|
|
1136
|
+
)
|
|
1137
|
+
: null,
|
|
1138
|
+
fileError ? h('div', { style: S.error }, fileError) : null,
|
|
1139
|
+
file
|
|
1140
|
+
? h('div', { style: S.card },
|
|
1141
|
+
h('div', { style: { ...S.line, justifyContent: 'space-between' } },
|
|
1142
|
+
h('strong', { style: { fontSize: 13 } }, file.path),
|
|
1143
|
+
h('span', { style: S.meta }, `${file.size} B · sha ${String(file.sha).slice(0, 7)}`),
|
|
1144
|
+
),
|
|
1145
|
+
editing
|
|
1146
|
+
? h('div', null,
|
|
1147
|
+
h('textarea', {
|
|
1148
|
+
style: { ...S.input, minHeight: 260, fontFamily: 'ui-monospace, Consolas, monospace', lineHeight: 1.5, marginTop: 8 },
|
|
1149
|
+
value: draft,
|
|
1150
|
+
spellCheck: false,
|
|
1151
|
+
onChange: (event) => setDraft(event.target.value),
|
|
1152
|
+
}),
|
|
1153
|
+
h('div', { style: { display: 'flex', gap: 8, marginTop: 8, flexWrap: 'wrap' } },
|
|
1154
|
+
h('input', { style: { ...S.input, flex: 1, minWidth: 180 }, value: commitMessage, placeholder: `chore: update ${file.path}`, onChange: (event) => setCommitMessage(event.target.value) }),
|
|
1155
|
+
h('button', { style: S.primary, disabled: busy === 'save', onClick: saveFile }, busy === 'save' ? '提交中…' : '提交并直接进默认分支'),
|
|
1156
|
+
h('button', { style: S.button, onClick: () => { setEditing(false); setDraft('') } }, '放弃'),
|
|
1157
|
+
h('button', { style: S.button, disabled: busy === 'file', onClick: () => openFile(file.path) }, '重新读取远端版本'),
|
|
1158
|
+
),
|
|
1159
|
+
h('p', { style: S.notice }, '提交会直接写到仓库的默认分支(不自动开 PR)。若远端在你编辑期间有改动,提交会被拒绝并提示冲突,此时先「重新读取远端版本」,草稿仍在编辑框里。'),
|
|
1160
|
+
)
|
|
1161
|
+
: h('div', null,
|
|
1162
|
+
h('pre', { style: S.pre }, file.text),
|
|
1163
|
+
h('div', { style: { display: 'flex', gap: 8, marginTop: 8 } },
|
|
1164
|
+
h('button', { style: S.button, onClick: () => { setEditing(true); setDraft(file.text) } }, '编辑'),
|
|
1165
|
+
),
|
|
1166
|
+
),
|
|
1167
|
+
)
|
|
1168
|
+
: null,
|
|
1169
|
+
)
|
|
1170
|
+
: null,
|
|
1171
|
+
|
|
1172
|
+
tab === 'inbox'
|
|
1173
|
+
? h('div', null,
|
|
1174
|
+
h('div', { style: { display: 'flex', gap: 8, marginBottom: 10, flexWrap: 'wrap' } },
|
|
1175
|
+
h('span', { style: { ...S.meta, alignSelf: 'center' } }, selectedRepo || targetRepoFull() || '未选仓库'),
|
|
1176
|
+
h('button', { style: S.button, disabled: busy === 'inbox', onClick: loadInbox }, busy === 'inbox' ? '拉取中…' : '拉取'),
|
|
1177
|
+
),
|
|
1178
|
+
inbox.errors && inbox.errors.length
|
|
1179
|
+
? inbox.errors.map((item, index) => h('div', { key: index, style: S.warn }, item))
|
|
1180
|
+
: null,
|
|
1181
|
+
inbox.issues
|
|
1182
|
+
? h('div', { style: S.card },
|
|
1183
|
+
h('strong', { style: { fontSize: 13 } }, `Issues (${inbox.issues.returned})`),
|
|
1184
|
+
inbox.issues.items.map((item) =>
|
|
1185
|
+
h('div', { key: item.number, style: S.row },
|
|
1186
|
+
h('span', { style: { ...S.meta, width: 46 } }, `#${item.number}`),
|
|
1187
|
+
h('span', { style: S.name }, item.title),
|
|
1188
|
+
h('span', { style: S.meta }, item.isPullRequest ? 'PR' : item.user),
|
|
1189
|
+
h('button', { style: { ...S.button, padding: '1px 8px', fontSize: 11 }, disabled: busy === 'issue', onClick: () => toggleIssue(item) }, item.state === 'open' ? '关闭' : '重开'),
|
|
1190
|
+
),
|
|
1191
|
+
),
|
|
1192
|
+
)
|
|
1193
|
+
: null,
|
|
1194
|
+
inbox.pulls
|
|
1195
|
+
? h('div', { style: S.card },
|
|
1196
|
+
h('strong', { style: { fontSize: 13 } }, `Pull requests (${inbox.pulls.returned})`),
|
|
1197
|
+
inbox.pulls.items.map((item) =>
|
|
1198
|
+
h('div', { key: item.number, style: { ...S.row, cursor: 'pointer' }, onClick: () => openPull(item.number) },
|
|
1199
|
+
h('span', { style: { ...S.meta, width: 46 } }, `#${item.number}`),
|
|
1200
|
+
h('span', { style: S.name }, item.title),
|
|
1201
|
+
h('span', { style: S.meta }, `${item.head} → ${item.base}`),
|
|
1202
|
+
),
|
|
1203
|
+
),
|
|
1204
|
+
)
|
|
1205
|
+
: null,
|
|
1206
|
+
inbox.runs
|
|
1207
|
+
? h('div', { style: S.card },
|
|
1208
|
+
h('strong', { style: { fontSize: 13 } }, `Actions (${inbox.runs.items.length})`),
|
|
1209
|
+
inbox.runs.items.map((item) =>
|
|
1210
|
+
h('div', { key: item.id, style: S.row },
|
|
1211
|
+
h('span', { style: S.name }, item.name),
|
|
1212
|
+
h('span', { style: S.meta }, `${item.status}${item.conclusion ? ` / ${item.conclusion}` : ''}`),
|
|
1213
|
+
h('span', { style: S.meta }, item.branch || ''),
|
|
1214
|
+
h('button', { style: { ...S.button, padding: '1px 8px', fontSize: 11 }, disabled: busy === 'log', onClick: () => showLog(item.id) }, '日志'),
|
|
1215
|
+
),
|
|
1216
|
+
),
|
|
1217
|
+
)
|
|
1218
|
+
: null,
|
|
1219
|
+
runLog
|
|
1220
|
+
? h('div', { style: S.card },
|
|
1221
|
+
h('div', { style: { ...S.line, justifyContent: 'space-between' } },
|
|
1222
|
+
h('strong', { style: { fontSize: 13 } }, `日志 · ${runLog.name || runLog.runId}`),
|
|
1223
|
+
h('button', { style: { ...S.button, padding: '1px 8px', fontSize: 11 }, onClick: () => setRunLog(null) }, '关闭'),
|
|
1224
|
+
),
|
|
1225
|
+
h('pre', { style: S.pre }, runLog.tail),
|
|
1226
|
+
)
|
|
1227
|
+
: null,
|
|
1228
|
+
pullDetail
|
|
1229
|
+
? h('div', { style: S.card },
|
|
1230
|
+
h('div', { style: { ...S.line, justifyContent: 'space-between' } },
|
|
1231
|
+
h('strong', { style: { fontSize: 13 } }, `#${pullDetail.number} ${pullDetail.title}`),
|
|
1232
|
+
h('span', { style: S.badge(pullDetail.mergeableState === 'clean' || pullDetail.mergeable) }, `${pullDetail.state} · ${pullDetail.mergeableState || '?'}`),
|
|
1233
|
+
),
|
|
1234
|
+
h('div', { style: S.line }, h('span', { style: S.label }, '分支'), h('span', { style: S.value }, `${pullDetail.head} → ${pullDetail.base}`)),
|
|
1235
|
+
h('div', { style: S.line }, h('span', { style: S.label }, '变更'), h('span', { style: S.value }, `+${pullDetail.additions} / -${pullDetail.deletions} · ${pullDetail.changedFiles} 个文件`)),
|
|
1236
|
+
pullDetail.body ? h('pre', { style: S.pre }, pullDetail.body) : null,
|
|
1237
|
+
pullDetail.files.map((file) =>
|
|
1238
|
+
h('div', { key: file.path, style: { marginTop: 8 } },
|
|
1239
|
+
h('div', { style: { ...S.meta } }, `${file.path} · ${file.status} +${file.additions}/-${file.deletions} · 行内评论示例:`, h('code', null, `${file.path}#1`)),
|
|
1240
|
+
h('pre', { style: { ...S.pre, maxHeight: 220 } }, file.patch || '(二进制或过大,无 patch)'),
|
|
1241
|
+
),
|
|
1242
|
+
),
|
|
1243
|
+
h('div', { style: { display: 'flex', gap: 6, marginTop: 10, flexWrap: 'wrap' } },
|
|
1244
|
+
h('input', { style: { ...S.input, flex: 1, minWidth: 200 }, value: inlineTarget, placeholder: '行内评论:path#line,例如 src/index.js#42', onChange: (event) => setInlineTarget(event.target.value) }),
|
|
1245
|
+
h('button', { style: S.button, disabled: busy === 'comment', onClick: () => sendPullComment(true) }, '行内评论'),
|
|
1246
|
+
),
|
|
1247
|
+
h('div', { style: { display: 'flex', gap: 6, marginTop: 8, flexWrap: 'wrap' } },
|
|
1248
|
+
h('input', { style: { ...S.input, flex: 1, minWidth: 200 }, value: commentDraft, placeholder: '会话评论', onChange: (event) => setCommentDraft(event.target.value) }),
|
|
1249
|
+
h('button', { style: S.button, disabled: busy === 'comment', onClick: () => sendPullComment(false) }, '发表评论'),
|
|
1250
|
+
),
|
|
1251
|
+
h('div', { style: { display: 'flex', gap: 6, marginTop: 8, flexWrap: 'wrap' } },
|
|
1252
|
+
h('input', { style: { ...S.input, flex: 1, minWidth: 200 }, value: reviewNote, placeholder: 'review 说明(请求修改必填)', onChange: (event) => setReviewNote(event.target.value) }),
|
|
1253
|
+
h('button', { style: S.primary, disabled: busy === 'review', onClick: () => sendReview('APPROVE') }, '批准'),
|
|
1254
|
+
h('button', { style: S.button, disabled: busy === 'review', onClick: () => sendReview('REQUEST_CHANGES') }, '请求修改'),
|
|
1255
|
+
h('button', { style: S.button, disabled: busy === 'review', onClick: () => sendReview('COMMENT') }, '仅评论'),
|
|
1256
|
+
),
|
|
1257
|
+
h('div', { style: { display: 'flex', gap: 6, marginTop: 8, flexWrap: 'wrap' } },
|
|
1258
|
+
h('button', {
|
|
1259
|
+
style: S.danger,
|
|
1260
|
+
disabled: busy === 'merge',
|
|
1261
|
+
onClick: () => {
|
|
1262
|
+
if (!window.confirm(`合并 #${pullDetail.number}(squash)?`)) return
|
|
1263
|
+
void run('merge', async () => {
|
|
1264
|
+
const ref = repoRef()
|
|
1265
|
+
await api('pull/merge', { ...ref, number: pullDetail.number, method: 'squash', confirm: true })
|
|
1266
|
+
await openPull(pullDetail.number)
|
|
1267
|
+
})
|
|
1268
|
+
},
|
|
1269
|
+
}, '合并(squash)'),
|
|
1270
|
+
h('button', { style: { ...S.button, padding: '1px 8px', fontSize: 11 }, onClick: () => setPullDetail(null) }, '收起'),
|
|
1271
|
+
),
|
|
1272
|
+
)
|
|
1273
|
+
: null,
|
|
1274
|
+
)
|
|
1275
|
+
: null,
|
|
1276
|
+
|
|
1277
|
+
tab === 'publish'
|
|
1278
|
+
? h('div', null,
|
|
1279
|
+
h('div', { style: S.card },
|
|
1280
|
+
h('strong', { style: { fontSize: 13 } }, '把它发到 GitHub'),
|
|
1281
|
+
h('label', { style: { display: 'block', margin: '10px 0 4px', fontSize: 12, color: 'var(--dsw-alias-label-secondary)' } }, '1. 要发布的插件'),
|
|
1282
|
+
h('input', { style: S.input, value: publishDir, placeholder: '插件目录,例如 …\\my-plugin', onChange: (event) => setPublishDir(event.target.value) }),
|
|
1283
|
+
discovered && discovered.items && discovered.items.length
|
|
1284
|
+
? h('div', { style: { display: 'flex', gap: 6, flexWrap: 'wrap', marginTop: 6 } },
|
|
1285
|
+
h('span', { style: { ...S.meta, alignSelf: 'center' } }, '或从本地发现里选:'),
|
|
1286
|
+
discovered.items.slice(0, 4).map((item) =>
|
|
1287
|
+
h('button', { key: item.dir, style: { ...S.button, padding: '2px 8px', fontSize: 12 }, disabled: Boolean(preflightingDir), onClick: () => useCandidate(item) }, item.name || item.dir),
|
|
1288
|
+
),
|
|
1289
|
+
)
|
|
1290
|
+
: null,
|
|
1291
|
+
h('label', { style: { display: 'block', margin: '10px 0 4px', fontSize: 12, color: 'var(--dsw-alias-label-secondary)' } }, '2. 发布到哪个账号'),
|
|
1292
|
+
targetOwner
|
|
1293
|
+
? h('div', { style: { ...S.line, padding: '2px 0' } },
|
|
1294
|
+
h('span', { style: S.value }, targetOwner),
|
|
1295
|
+
h('span', { style: S.meta }, status && status.installation ? `installation ${status.installation.id}` : ''),
|
|
1296
|
+
)
|
|
1297
|
+
: !status || !status.configured
|
|
1298
|
+
? h('button', { style: S.primary, disabled: busy === 'register', onClick: () => registerApp(false) }, busy === 'register' ? '准备中…' : '连接 GitHub(点一次)')
|
|
1299
|
+
: h('div', null,
|
|
1300
|
+
h('a', { href: installUrl, target: '_blank', rel: 'noreferrer', style: { ...S.primary, display: 'inline-block', textDecoration: 'none' } }, '打开 App 安装页'),
|
|
1301
|
+
h('p', { style: S.notice }, 'App 已注册但还没安装到账号;装完几秒后这里会自动变成账号名。'),
|
|
1302
|
+
),
|
|
1303
|
+
h('label', { style: { display: 'block', margin: '10px 0 4px', fontSize: 12, color: 'var(--dsw-alias-label-secondary)' } }, '3. 仓库名'),
|
|
1304
|
+
h('input', { style: S.input, value: repoTarget, placeholder: 'my-plugin', onChange: (event) => { setRepoTarget(event.target.value); setRepoTargetEdited(true) } }),
|
|
1305
|
+
targetOwner && repoTarget
|
|
1306
|
+
? h('p', { style: S.notice }, '将发布到:', h('strong', null, `${targetOwner}/${repoTarget}`))
|
|
1307
|
+
: null,
|
|
1308
|
+
h('p', { style: { ...S.warn, fontSize: 12 } }, '目标仓库必须已经存在,并且已经授权给这个 App;插件不会替你新建仓库。'),
|
|
1309
|
+
createRepoUrl
|
|
1310
|
+
? h('p', { style: S.notice },
|
|
1311
|
+
'还没有这个仓库?',
|
|
1312
|
+
h('a', { href: createRepoUrl, target: '_blank', rel: 'noreferrer', style: { color: 'var(--dsw-alias-brand-primary)' } }, '在 GitHub 上建一个同名仓库'),
|
|
1313
|
+
',建好后回 GitHub 把新仓库勾进这个 App 的安装范围,再回来点发布。',
|
|
1314
|
+
)
|
|
1315
|
+
: null,
|
|
1316
|
+
h('div', { style: { display: 'flex', gap: 8, marginTop: 12, flexWrap: 'wrap' } },
|
|
1317
|
+
h('button', { style: S.button, disabled: busy === 'preflight', onClick: () => { void runPreflight() } }, preflightingDir ? '体检中…' : '先体检(不推送文件)'),
|
|
1318
|
+
h('button', { style: S.primary, disabled: busy === 'publish' || !targetOwner, onClick: startPublish }, busy === 'publish' ? '发布中…' : '发布到 GitHub'),
|
|
1319
|
+
),
|
|
1320
|
+
!targetOwner
|
|
1321
|
+
? h('p', { style: S.notice }, '按钮灰着是因为还没完成第 2 步。')
|
|
1322
|
+
: null,
|
|
1323
|
+
h('button', { style: { ...S.button, marginTop: 10, padding: '3px 10px', fontSize: 12 }, onClick: () => setShowAdvanced((value) => !value) },
|
|
1324
|
+
showAdvanced ? '收起高级设置' : '高级设置(分支 / 说明)'),
|
|
1325
|
+
showAdvanced
|
|
1326
|
+
? h('div', null,
|
|
1327
|
+
h('label', { style: { display: 'block', margin: '10px 0 4px', fontSize: 12, color: 'var(--dsw-alias-label-secondary)' } }, `分支(默认 ${status && status.publish ? status.publish.branch : 'main'})`),
|
|
1328
|
+
h('input', { style: S.input, value: publishBranch, placeholder: status && status.publish ? status.publish.branch : 'main', onChange: (event) => setPublishBranch(event.target.value) }),
|
|
1329
|
+
h('label', { style: { display: 'block', margin: '10px 0 4px', fontSize: 12, color: 'var(--dsw-alias-label-secondary)' } }, 'Release 说明(可留空)'),
|
|
1330
|
+
h('textarea', { style: { ...S.input, minHeight: 70 }, value: publishNotes, onChange: (event) => setPublishNotes(event.target.value) }),
|
|
1331
|
+
h('p', { style: S.notice }, `发布会在仓库上设置 ${status && status.publish ? status.publish.topic : 'dsh-plugin'} topic,供插件市场索引抓取。`),
|
|
1332
|
+
h('div', { style: { borderTop: '1px solid var(--dsw-alias-border-l1)', marginTop: 12, paddingTop: 10 } },
|
|
1333
|
+
h('div', { style: { ...S.line, justifyContent: 'space-between' } },
|
|
1334
|
+
h('strong', { style: { fontSize: 12 } }, '可选:发到 npm(需要 npm 通行密钥)'),
|
|
1335
|
+
npmState ? h('span', { style: S.badge(npmState.phase === 'ready') }, NPM_PHASE[npmState.phase] || npmState.phase) : null,
|
|
1336
|
+
),
|
|
1337
|
+
h('div', { style: { display: 'flex', gap: 8, flexWrap: 'wrap', marginTop: 8 } },
|
|
1338
|
+
h('button', { style: S.button, disabled: busy === 'npmstate' || !targetOwner, onClick: loadNpmState }, busy === 'npmstate' ? '检查中…' : '检查状态'),
|
|
1339
|
+
h('button', { style: S.button, disabled: busy === 'npm' || !targetOwner, onClick: runNpmPublish }, busy === 'npm' ? '处理中…' : '生成 workflow 并触发发布'),
|
|
1340
|
+
npmState && npmState.urls && npmState.urls.secrets
|
|
1341
|
+
? h('a', { href: npmState.urls.secrets, target: '_blank', rel: 'noreferrer', style: { ...S.button, textDecoration: 'none', display: 'inline-block' } }, '打开 Secrets 页面')
|
|
1342
|
+
: null,
|
|
1343
|
+
npmState && npmState.urls && npmState.urls.trustedPublisher
|
|
1344
|
+
? h('a', { href: npmState.urls.trustedPublisher, target: '_blank', rel: 'noreferrer', style: { ...S.button, textDecoration: 'none', display: 'inline-block' } }, '打开 Trusted Publisher')
|
|
1345
|
+
: null,
|
|
1346
|
+
),
|
|
1347
|
+
npmState && npmState.phase === 'needs-first-publish'
|
|
1348
|
+
? h('div', null,
|
|
1349
|
+
h('p', { style: S.warn }, '如果 npm 要求通行密钥而你的手机/电脑连不上:跳过 npm,用上面的「分发(不需要 npm)」。npm 只是额外渠道,不是 DSH 插件的必需项。'),
|
|
1350
|
+
h('p', { style: S.notice }, '仍然想发 npm 的话,按顺序做:'),
|
|
1351
|
+
h('ol', { style: { ...S.notice, paddingLeft: 20, margin: '4px 0', lineHeight: 1.8 } },
|
|
1352
|
+
(npmState.steps || []).map((step, index) => h('li', { key: index }, step)),
|
|
1353
|
+
),
|
|
1354
|
+
npmState.fields && npmState.fields.length
|
|
1355
|
+
? h('div', { style: { border: '1px solid var(--dsw-alias-border-l1)', borderRadius: 8, marginTop: 8, overflow: 'hidden' } },
|
|
1356
|
+
h('div', { style: { padding: '5px 10px', fontSize: 11, color: 'var(--dsw-alias-label-secondary)', background: 'var(--dsw-alias-bg-layer-2)' } }, 'npm 表单对照表(按顺序从上往下核一遍)'),
|
|
1357
|
+
npmState.fields.map((field, index) =>
|
|
1358
|
+
h('div', { key: index, style: { display: 'grid', gridTemplateColumns: '1.05fr 1fr', gap: 8, padding: '5px 10px', fontSize: 12, borderTop: '1px solid var(--dsw-alias-border-l1)' } },
|
|
1359
|
+
h('span', { style: { color: 'var(--dsw-alias-label-secondary)' } }, field.label),
|
|
1360
|
+
h('span', null,
|
|
1361
|
+
field.label === 'Token name' ? h(CopyValue, { value: field.value }) : field.value,
|
|
1362
|
+
field.note ? h('span', { style: { color: 'var(--dsw-alias-label-secondary)', marginLeft: 6 } }, `· ${field.note}`) : null,
|
|
1363
|
+
),
|
|
1364
|
+
),
|
|
1365
|
+
),
|
|
1366
|
+
)
|
|
1367
|
+
: null,
|
|
1368
|
+
h('p', { style: S.notice }, 'secret 的名字必须是:', h(CopyValue, { value: 'NPM_TOKEN' })),
|
|
1369
|
+
npmState.urls && npmState.urls.tokens
|
|
1370
|
+
? h('a', { href: npmState.urls.tokens, target: '_blank', rel: 'noreferrer', style: { fontSize: 12, color: 'var(--dsw-alias-brand-primary)' } }, '打开 npm 建 token 页面(已带你的用户名)')
|
|
1371
|
+
: null,
|
|
1372
|
+
)
|
|
1373
|
+
: null,
|
|
1374
|
+
npmState && npmState.phase === 'ready'
|
|
1375
|
+
? h('div', null,
|
|
1376
|
+
h('p', { style: S.notice }, '包已在 npm 上。把这些值填进 Trusted Publisher(填一次,以后不需要任何 token):'),
|
|
1377
|
+
h('div', null,
|
|
1378
|
+
h(CopyValue, { label: 'Provider', value: npmState.trustedPublisherValues.provider }),
|
|
1379
|
+
h(CopyValue, { label: 'Organization/user', value: npmState.trustedPublisherValues.userOrOrg }),
|
|
1380
|
+
h(CopyValue, { label: 'Repository', value: npmState.trustedPublisherValues.repository }),
|
|
1381
|
+
h(CopyValue, { label: 'Workflow filename', value: npmState.trustedPublisherValues.workflowFile }),
|
|
1382
|
+
h(CopyValue, { label: 'Allowed action', value: npmState.trustedPublisherValues.allowedAction }),
|
|
1383
|
+
),
|
|
1384
|
+
)
|
|
1385
|
+
: null,
|
|
1386
|
+
npmState && npmState.phase === 'needs-workflow'
|
|
1387
|
+
? h('p', { style: S.notice }, '包已在 npm 上,但仓库里还没有发布 workflow:点上面的「生成 workflow 并触发发布」即可。')
|
|
1388
|
+
: null,
|
|
1389
|
+
npmRun
|
|
1390
|
+
? h('p', { style: S.notice },
|
|
1391
|
+
`运行状态:${npmRun.status || 'unknown'}${npmRun.conclusion ? ` / ${npmRun.conclusion}` : ''}`,
|
|
1392
|
+
npmRun.url ? h('a', { href: npmRun.url, target: '_blank', rel: 'noreferrer', style: { marginLeft: 8, color: 'var(--dsw-alias-brand-primary)' } }, '打开 run') : null,
|
|
1393
|
+
)
|
|
1394
|
+
: null,
|
|
1395
|
+
),
|
|
1396
|
+
)
|
|
1397
|
+
: null,
|
|
1398
|
+
h('p', { style: S.notice }, '发布会把目录里的文件提交到这个仓库,建一个 v<版本> 的 Release,并检查是否已被市场收录。不会执行 npm install 或仓库里的任何脚本;同一版本重跑不会产生第二个 Release。'),
|
|
1399
|
+
),
|
|
1400
|
+
h(PreflightView, { report }),
|
|
1401
|
+
h(StepsView, { job }),
|
|
1402
|
+
h('div', { style: S.card },
|
|
1403
|
+
h('strong', { style: { fontSize: 13 } }, '分发(不需要 npm)'),
|
|
1404
|
+
h('p', { style: S.notice }, '把插件打包成 .tgz 挂到这次 Release 上,并给出钉住提交的 git 地址。Market 索引用的也是同一个 git 源,所以 Discover 安装同样不需要 npm。'),
|
|
1405
|
+
h('div', { style: { display: 'flex', gap: 8, flexWrap: 'wrap' } },
|
|
1406
|
+
h('button', { style: S.primary, disabled: busy === 'asset' || !targetOwner, onClick: makeReleaseAsset }, busy === 'asset' ? '打包中…' : '打包并挂到 Release'),
|
|
1407
|
+
h('button', { style: S.button, disabled: busy === 'readiness' || !targetOwner, onClick: checkReadiness }, busy === 'readiness' ? '检查中…' : '检查能否上 dshmarket'),
|
|
1408
|
+
),
|
|
1409
|
+
readiness
|
|
1410
|
+
? h('div', { style: { marginTop: 8 } },
|
|
1411
|
+
h('div', { style: { ...S.line, justifyContent: 'space-between' } },
|
|
1412
|
+
h('strong', { style: { fontSize: 12 } }, readiness.ready ? '可以提交到 dshmarket 了' : '还有阻断项未满足'),
|
|
1413
|
+
h('span', { style: S.badge(readiness.ready) }, readiness.ready ? 'ready' : 'blocked'),
|
|
1414
|
+
),
|
|
1415
|
+
readiness.checks.map((item) =>
|
|
1416
|
+
h('div', { key: item.id, style: S.line },
|
|
1417
|
+
h('span', { style: { ...S.meta, width: 14, flex: '0 0 auto', color: item.level === 'block' ? 'var(--dsw-alias-state-error-primary)' : item.level === 'warn' ? 'var(--dsw-alias-state-warn-primary)' : 'var(--dsw-alias-label-secondary)' } }, item.level === 'pass' ? '✓' : item.level === 'block' ? '✕' : item.level === 'warn' ? '!' : '·'),
|
|
1418
|
+
h('span', { style: S.value }, item.title, item.detail ? h('span', { style: S.meta }, ` — ${item.detail}`) : null),
|
|
1419
|
+
),
|
|
1420
|
+
),
|
|
1421
|
+
readiness.entry && readiness.entry.tarball
|
|
1422
|
+
? h(CopyValue, { label: '条目字段 tarball:', value: readiness.entry.tarball })
|
|
1423
|
+
: null,
|
|
1424
|
+
)
|
|
1425
|
+
: null,
|
|
1426
|
+
releaseAsset
|
|
1427
|
+
? h('div', null,
|
|
1428
|
+
releaseAsset.asset && releaseAsset.asset.uploaded
|
|
1429
|
+
? h('p', { style: S.notice }, `已上传 ${releaseAsset.asset.name}(${Math.round(releaseAsset.asset.size / 1024)} KB):`,
|
|
1430
|
+
h('a', { href: releaseAsset.asset.url, target: '_blank', rel: 'noreferrer', style: { marginLeft: 6, color: 'var(--dsw-alias-brand-primary)' } }, '下载'))
|
|
1431
|
+
: h('p', { style: S.warn }, `上传失败:${releaseAsset.asset ? releaseAsset.asset.reason : '未知原因'}`),
|
|
1432
|
+
releaseAsset.gitInstall ? h(CopyValue, { label: 'git 安装地址:', value: releaseAsset.gitInstall }) : null,
|
|
1433
|
+
)
|
|
1434
|
+
: null,
|
|
1435
|
+
),
|
|
1436
|
+
)
|
|
1437
|
+
: null,
|
|
1438
|
+
|
|
1439
|
+
tab === 'market'
|
|
1440
|
+
? h('div', null,
|
|
1441
|
+
h('div', { style: S.card },
|
|
1442
|
+
h('label', { style: { display: 'block', fontSize: 12, color: 'var(--dsw-alias-label-secondary)', marginBottom: 4 } }, '包名(npm 名,如 dsh-my-plugin)'),
|
|
1443
|
+
h('input', { style: S.input, value: probeName, placeholder: 'dsh-my-plugin', onChange: (event) => setProbeName(event.target.value) }),
|
|
1444
|
+
h('label', { style: { display: 'block', fontSize: 12, color: 'var(--dsw-alias-label-secondary)', margin: '10px 0 4px' } }, '版本号(探测 Release 用;体检后自动填入 package.json 的版本)'),
|
|
1445
|
+
h('input', { style: S.input, value: probeVersion, placeholder: '0.1.0', onChange: (event) => setProbeVersion(event.target.value) }),
|
|
1446
|
+
h('p', { style: S.notice }, `仓库取自发布页:${targetOwner ? `${targetOwner}/${repoTarget || '?'}` : '未连接账号(GitHub 侧两项会跳过)'}。探测失败一律记作「未知」,不判为未收录;收录通常滞后 1–2 天。`),
|
|
1447
|
+
h('div', { style: { display: 'flex', gap: 8, marginTop: 8 } },
|
|
1448
|
+
h('button', { style: S.button, disabled: busy === 'probe', onClick: runProbe }, busy === 'probe' ? '探测中…' : '探测'),
|
|
1449
|
+
),
|
|
1450
|
+
),
|
|
1451
|
+
probe
|
|
1452
|
+
? h('div', { style: S.card },
|
|
1453
|
+
h('div', { style: { ...S.line, justifyContent: 'space-between' } },
|
|
1454
|
+
h('strong', { style: { fontSize: 13 } }, '探测结果'),
|
|
1455
|
+
h('span', { style: S.badge(probe.summary === 'listed') }, PROBE_STATE[probe.summary] || probe.summary),
|
|
1456
|
+
),
|
|
1457
|
+
probe.results.map((item) =>
|
|
1458
|
+
h('div', { key: item.id, style: S.row },
|
|
1459
|
+
h('span', { style: S.name }, item.id),
|
|
1460
|
+
h('span', { style: { ...S.meta, width: 52 } }, PROBE_STATE[item.state] || item.state),
|
|
1461
|
+
h('span', { style: { ...S.meta, maxWidth: 240, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' } }, item.detail),
|
|
1462
|
+
),
|
|
1463
|
+
),
|
|
1464
|
+
)
|
|
1465
|
+
: null,
|
|
1466
|
+
h('div', { style: S.card },
|
|
1467
|
+
h('strong', { style: { fontSize: 13 } }, '自建市场索引'),
|
|
1468
|
+
h('p', { style: S.notice }, '在仓库里生成 format-1 的 market/index.json(Git 源 + 当前提交),你把自己的这个地址加进 DSH 插件市场源后,Discover 里就能直接看到并安装。'),
|
|
1469
|
+
h('div', { style: { display: 'flex', gap: 8, flexWrap: 'wrap' } },
|
|
1470
|
+
h('button', { style: S.button, disabled: busy === 'index' || !targetOwner, onClick: makeMarketIndex }, busy === 'index' ? '生成中…' : '生成 / 更新市场索引'),
|
|
1471
|
+
h('button', { style: S.primary, disabled: busy === 'attach', onClick: attachMarket }, busy === 'attach' ? '写入中…' : '一键加入 DSH 市场源'),
|
|
1472
|
+
),
|
|
1473
|
+
marketAttach
|
|
1474
|
+
? marketAttach.attached
|
|
1475
|
+
? h('p', { style: S.notice }, `已加入市场源:${marketAttach.url}${marketAttach.added ? '' : '(原本已在列表里)'}。打开设置 → 插件 → 发现即可看到。`)
|
|
1476
|
+
: h('div', null,
|
|
1477
|
+
h('p', { style: S.warn }, marketAttach.reason || '没能自动写入市场源'),
|
|
1478
|
+
marketAttach.url ? h(CopyValue, { label: '手动添加这个地址:', value: marketAttach.url }) : null,
|
|
1479
|
+
marketAttach.manual ? h('p', { style: S.notice }, marketAttach.manual) : null,
|
|
1480
|
+
)
|
|
1481
|
+
: null,
|
|
1482
|
+
marketIndex
|
|
1483
|
+
? h('div', null,
|
|
1484
|
+
h('p', { style: S.notice }, '本机可用地址(raw / CDN 在你的网络里不通时用这个,加进 DSH 市场源):',
|
|
1485
|
+
h('br'),
|
|
1486
|
+
h('span', { style: { color: 'var(--dsw-alias-brand-primary)', overflowWrap: 'anywhere' } },
|
|
1487
|
+
`${typeof window !== 'undefined' ? window.location.origin : ''}${marketIndex.localUrl || ''}`),
|
|
1488
|
+
),
|
|
1489
|
+
h('p', { style: S.notice }, '公开地址(分享给别人用):',
|
|
1490
|
+
h('br'),
|
|
1491
|
+
h('span', { style: { color: 'var(--dsw-alias-brand-primary)', overflowWrap: 'anywhere' } }, marketIndex.url),
|
|
1492
|
+
),
|
|
1493
|
+
h('p', { style: S.notice }, `安装标识:${marketIndex.installSpec}`),
|
|
1494
|
+
)
|
|
1495
|
+
: null,
|
|
1496
|
+
),
|
|
1497
|
+
)
|
|
1498
|
+
: null,
|
|
1499
|
+
)
|
|
1500
|
+
}
|
|
1501
|
+
|
|
1502
|
+
const Page = () => h('div', { style: S.page }, h(Console))
|
|
1503
|
+
|
|
1504
|
+
function SidebarIcon() {
|
|
1505
|
+
return h(
|
|
1506
|
+
'svg',
|
|
1507
|
+
{ width: 16, height: 16, viewBox: '0 0 36 36', 'aria-hidden': true, style: { display: 'block', color: 'currentColor' } },
|
|
1508
|
+
h('g', { fill: 'currentColor' },
|
|
1509
|
+
h('path', { d: 'M18 17.2 22.9 22.1 18 27 13.1 22.1Z' }),
|
|
1510
|
+
h('rect', { x: 16.6, y: 11.8, width: 2.8, height: 6.6, rx: 1 }),
|
|
1511
|
+
h('path', { d: 'M18 9.4 21.9 13.5 14.1 13.5Z' }),
|
|
1512
|
+
),
|
|
1513
|
+
)
|
|
1514
|
+
}
|
|
1515
|
+
|
|
1516
|
+
function SettingsIcon() {
|
|
1517
|
+
return h(
|
|
1518
|
+
'svg',
|
|
1519
|
+
{ width: 16, height: 16, viewBox: '0 0 36 36', 'aria-hidden': true, style: { display: 'block', color: 'currentColor' } },
|
|
1520
|
+
h('g', { fill: 'currentColor' },
|
|
1521
|
+
h('path', { d: 'M18 17.2 22.9 22.1 18 27 13.1 22.1Z' }),
|
|
1522
|
+
h('rect', { x: 16.6, y: 11.8, width: 2.8, height: 6.6, rx: 1 }),
|
|
1523
|
+
h('path', { d: 'M18 9.4 21.9 13.5 14.1 13.5Z' }),
|
|
1524
|
+
),
|
|
1525
|
+
)
|
|
1526
|
+
}
|
|
1527
|
+
|
|
1528
|
+
return {
|
|
1529
|
+
inject: ['slots'],
|
|
1530
|
+
apply(ctx) {
|
|
1531
|
+
ctx.slots.inject('sidebar.panellist', () =>
|
|
1532
|
+
ctx.slots.register({ name: 'sidebar.panellist', id: 'github-console', order: 31, label: 'GitHub 控制台' }, SidebarIcon),
|
|
1533
|
+
)
|
|
1534
|
+
ctx.slots.inject('main', () =>
|
|
1535
|
+
ctx.slots.register({ name: 'main', key: 'github-console' }, Page),
|
|
1536
|
+
)
|
|
1537
|
+
ctx.slots.inject('settings.section', () =>
|
|
1538
|
+
ctx.slots.register({ name: 'settings.section', id: 'github-console', order: 31, label: 'GitHub 控制台' }, Console),
|
|
1539
|
+
)
|
|
1540
|
+
ctx.slots.inject('settings.section.icon', () =>
|
|
1541
|
+
ctx.slots.register({ name: 'settings.section.icon', id: 'github-console' }, SettingsIcon),
|
|
1542
|
+
)
|
|
1543
|
+
},
|
|
1544
|
+
}
|
|
1545
|
+
},
|
|
1546
|
+
})
|