dsh-github-console 0.4.1 → 0.5.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/client.js +107 -2
- package/index.js +360 -27
- package/package.json +1 -1
package/client.js
CHANGED
|
@@ -245,6 +245,10 @@ window.__ModuleLoader__.load({
|
|
|
245
245
|
const [reviewNote, setReviewNote] = useState('')
|
|
246
246
|
const [inlineTarget, setInlineTarget] = useState('')
|
|
247
247
|
const [runLog, setRunLog] = useState(null)
|
|
248
|
+
const [searchQuery, setSearchQuery] = useState('')
|
|
249
|
+
const [searchResults, setSearchResults] = useState(null)
|
|
250
|
+
const [commits, setCommits] = useState(null)
|
|
251
|
+
const [notifications, setNotifications] = useState(null)
|
|
248
252
|
|
|
249
253
|
const [publishDir, setPublishDir] = useState('')
|
|
250
254
|
const [report, setReport] = useState(null)
|
|
@@ -522,8 +526,39 @@ window.__ModuleLoader__.load({
|
|
|
522
526
|
})
|
|
523
527
|
}
|
|
524
528
|
|
|
525
|
-
const
|
|
529
|
+
const runCodeSearch = () => {
|
|
530
|
+
if (!searchQuery.trim()) {
|
|
531
|
+
setError('先输入搜索词')
|
|
532
|
+
return
|
|
533
|
+
}
|
|
534
|
+
const ref = repoRef()
|
|
535
|
+
void run('search', async () => {
|
|
536
|
+
setSearchResults(await api('search/code', { q: searchQuery.trim(), ...(ref || {}) }))
|
|
537
|
+
})
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
const loadCommits = () => {
|
|
526
541
|
const ref = repoRef()
|
|
542
|
+
if (!ref) return
|
|
543
|
+
void run('commits', async () => {
|
|
544
|
+
setCommits(await api('commits', { ...ref, limit: 20 }))
|
|
545
|
+
})
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
const loadNotifications = () => {
|
|
549
|
+
void run('notice', async () => {
|
|
550
|
+
setNotifications(await api('notifications', { limit: 30 }))
|
|
551
|
+
})
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
const readAllNotifications = () => {
|
|
555
|
+
void run('notice-read', async () => {
|
|
556
|
+
await api('notifications/read', { all: true })
|
|
557
|
+
setNotifications(await api('notifications', { limit: 30 }))
|
|
558
|
+
})
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
const toggleIssue = (item) => { const ref = repoRef()
|
|
527
562
|
if (!ref) return
|
|
528
563
|
void run('issue', async () => {
|
|
529
564
|
await api('issue/update', { ...ref, number: item.number, state: item.state === 'open' ? 'closed' : 'open' })
|
|
@@ -990,7 +1025,18 @@ window.__ModuleLoader__.load({
|
|
|
990
1025
|
}, '撤销用户授权')
|
|
991
1026
|
: null,
|
|
992
1027
|
),
|
|
993
|
-
authMessage ? h('p', { style: S.notice }, authMessage) : null,
|
|
1028
|
+
authMessage ? h('p', { style: /失败|没有|拒绝|过期|不能|需要/.test(authMessage) ? S.warn : S.notice }, authMessage) : null,
|
|
1029
|
+
status && status.app && status.app.slug
|
|
1030
|
+
? h('p', { style: S.notice },
|
|
1031
|
+
'App 设置页(Device Flow / 回调地址都在这里):',
|
|
1032
|
+
h('a', {
|
|
1033
|
+
href: `https://github.com/settings/apps/${status.app.slug}`,
|
|
1034
|
+
target: '_blank',
|
|
1035
|
+
rel: 'noreferrer',
|
|
1036
|
+
style: { color: 'var(--dsw-alias-brand-primary)', overflowWrap: 'anywhere' },
|
|
1037
|
+
}, `github.com/settings/apps/${status.app.slug}`),
|
|
1038
|
+
)
|
|
1039
|
+
: null,
|
|
994
1040
|
device
|
|
995
1041
|
? h('p', { style: S.notice },
|
|
996
1042
|
'在浏览器打开 ',
|
|
@@ -1000,6 +1046,16 @@ window.__ModuleLoader__.load({
|
|
|
1000
1046
|
' 并确认。插件会自动轮询结果。',
|
|
1001
1047
|
)
|
|
1002
1048
|
: null,
|
|
1049
|
+
h('p', { style: S.notice },
|
|
1050
|
+
'按钮没反应?直接打开这个页面授权(不依赖面板):',
|
|
1051
|
+
h('br'),
|
|
1052
|
+
h('a', {
|
|
1053
|
+
href: '/github-console/device',
|
|
1054
|
+
target: '_blank',
|
|
1055
|
+
rel: 'noreferrer',
|
|
1056
|
+
style: { color: 'var(--dsw-alias-brand-primary)', overflowWrap: 'anywhere' },
|
|
1057
|
+
}, `${typeof window !== 'undefined' ? window.location.origin : ''}/github-console/device`),
|
|
1058
|
+
),
|
|
1003
1059
|
status && status.auth && status.auth.capabilities
|
|
1004
1060
|
? h('div', { style: { marginTop: 6 } },
|
|
1005
1061
|
h('div', { style: S.meta }, '当前连接的能力'),
|
|
@@ -1103,6 +1159,34 @@ window.__ModuleLoader__.load({
|
|
|
1103
1159
|
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
1160
|
h('button', { style: S.button, disabled: busy === 'repos', onClick: loadRepos }, busy === 'repos' ? '查询中…' : '查询'),
|
|
1105
1161
|
),
|
|
1162
|
+
h('div', { style: { display: 'flex', gap: 6, marginBottom: 8, flexWrap: 'wrap' } },
|
|
1163
|
+
h('input', { style: { ...S.input, flex: 1, minWidth: 180 }, value: searchQuery, placeholder: '代码搜索(需要用户连接;按当前仓库限定)', onChange: (event) => setSearchQuery(event.target.value), onKeyDown: (event) => { if (event.key === 'Enter') runCodeSearch() } }),
|
|
1164
|
+
h('button', { style: S.button, disabled: busy === 'search', onClick: runCodeSearch }, busy === 'search' ? '搜索中…' : '搜索'),
|
|
1165
|
+
h('button', { style: S.button, disabled: busy === 'commits', onClick: loadCommits }, busy === 'commits' ? '读取中…' : '提交历史'),
|
|
1166
|
+
),
|
|
1167
|
+
searchResults
|
|
1168
|
+
? h('div', { style: S.card },
|
|
1169
|
+
h('strong', { style: { fontSize: 13 } }, `代码搜索:${searchResults.total} 条`),
|
|
1170
|
+
searchResults.items.map((item) =>
|
|
1171
|
+
h('div', { key: item.sha + item.path, style: S.row },
|
|
1172
|
+
h('span', { style: S.name }, item.path),
|
|
1173
|
+
h('span', { style: S.meta }, item.repo),
|
|
1174
|
+
),
|
|
1175
|
+
),
|
|
1176
|
+
)
|
|
1177
|
+
: null,
|
|
1178
|
+
commits
|
|
1179
|
+
? h('div', { style: S.card },
|
|
1180
|
+
h('strong', { style: { fontSize: 13 } }, `提交历史(${commits.items.length})`),
|
|
1181
|
+
commits.items.map((item) =>
|
|
1182
|
+
h('div', { key: item.sha, style: S.row },
|
|
1183
|
+
h('span', { style: { ...S.meta, width: 64 } }, item.short),
|
|
1184
|
+
h('span', { style: S.name }, item.message),
|
|
1185
|
+
h('span', { style: S.meta }, `${item.author} · ${(item.date || '').slice(0, 10)}`),
|
|
1186
|
+
),
|
|
1187
|
+
),
|
|
1188
|
+
)
|
|
1189
|
+
: null,
|
|
1106
1190
|
!reposLoaded
|
|
1107
1191
|
? h('p', { style: S.notice }, '点「查询」列出 App 安装范围内的仓库。')
|
|
1108
1192
|
: repos.length === 0
|
|
@@ -1178,6 +1262,27 @@ window.__ModuleLoader__.load({
|
|
|
1178
1262
|
inbox.errors && inbox.errors.length
|
|
1179
1263
|
? inbox.errors.map((item, index) => h('div', { key: index, style: S.warn }, item))
|
|
1180
1264
|
: null,
|
|
1265
|
+
h('div', { style: S.card },
|
|
1266
|
+
h('div', { style: { ...S.line, justifyContent: 'space-between' } },
|
|
1267
|
+
h('strong', { style: { fontSize: 13 } }, '通知'),
|
|
1268
|
+
h('div', { style: { display: 'flex', gap: 6 } },
|
|
1269
|
+
h('button', { style: { ...S.button, padding: '1px 8px', fontSize: 11 }, disabled: busy === 'notice', onClick: loadNotifications }, '拉取'),
|
|
1270
|
+
h('button', { style: { ...S.button, padding: '1px 8px', fontSize: 11 }, disabled: busy === 'notice-read', onClick: readAllNotifications }, '全部已读'),
|
|
1271
|
+
),
|
|
1272
|
+
),
|
|
1273
|
+
h('p', { style: S.notice }, '通知只有「个人访问令牌 / 环境变量」连接能读;GitHub 不对 App 令牌开放这个接口。'),
|
|
1274
|
+
notifications
|
|
1275
|
+
? notifications.items.length
|
|
1276
|
+
? notifications.items.map((item) =>
|
|
1277
|
+
h('div', { key: item.id, style: S.row },
|
|
1278
|
+
h('span', { style: { ...S.meta, width: 64 } }, item.reason),
|
|
1279
|
+
h('span', { style: S.name }, item.title || item.type),
|
|
1280
|
+
h('span', { style: S.meta }, item.repo),
|
|
1281
|
+
),
|
|
1282
|
+
)
|
|
1283
|
+
: h('p', { style: S.notice }, `没有未读通知(${notifications.count} 条)`)
|
|
1284
|
+
: null,
|
|
1285
|
+
),
|
|
1181
1286
|
inbox.issues
|
|
1182
1287
|
? h('div', { style: S.card },
|
|
1183
1288
|
h('strong', { style: { fontSize: 13 } }, `Issues (${inbox.issues.returned})`),
|
package/index.js
CHANGED
|
@@ -23,7 +23,7 @@ import zlib from 'node:zlib'
|
|
|
23
23
|
import { fileURLToPath } from 'node:url'
|
|
24
24
|
import { promises as dnsPromises, Resolver } from 'node:dns'
|
|
25
25
|
|
|
26
|
-
const PLUGIN_VERSION = '0.
|
|
26
|
+
const PLUGIN_VERSION = '0.5.0'
|
|
27
27
|
const APP_CRED = 'github-console/app'
|
|
28
28
|
const INSTALL_CRED = 'github-console/install'
|
|
29
29
|
const BRIDGE_CRED = 'github-console/bridge'
|
|
@@ -279,37 +279,51 @@ function readUntil(socket, separator, timeoutMs) {
|
|
|
279
279
|
* system hosts file. GitHub accelerators rewrite hosts to 127.0.0.1 and answer
|
|
280
280
|
* with their own CA, which Node does not trust; skipping hosts sidesteps both.
|
|
281
281
|
*/
|
|
282
|
-
function makeBypassLookup(servers) {
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
resolver.setServers(servers)
|
|
286
|
-
} catch {
|
|
287
|
-
/* keep default servers */
|
|
288
|
-
}
|
|
289
|
-
// One publish writes ~10 blobs; resolving the host for every request both
|
|
290
|
-
// wastes time and multiplies the chance of a transient DNS timeout.
|
|
282
|
+
function makeBypassLookup(servers, goodIps) {
|
|
283
|
+
// Answers differ per public resolver (one may hand back an unroutable IP), so
|
|
284
|
+
// merge them all and prefer whatever address actually worked last.
|
|
291
285
|
const cache = new Map()
|
|
292
286
|
const ttlMs = 5 * 60 * 1000
|
|
287
|
+
|
|
288
|
+
const resolveAll = (hostname) =>
|
|
289
|
+
Promise.all(
|
|
290
|
+
servers.map(
|
|
291
|
+
(server) =>
|
|
292
|
+
new Promise((resolve) => {
|
|
293
|
+
const resolver = new Resolver({ timeout: 2500, tries: 1 })
|
|
294
|
+
try {
|
|
295
|
+
resolver.setServers([server])
|
|
296
|
+
} catch {
|
|
297
|
+
resolve([])
|
|
298
|
+
return
|
|
299
|
+
}
|
|
300
|
+
resolver.resolve4(hostname, (error, list) => resolve(error || !list ? [] : list))
|
|
301
|
+
}),
|
|
302
|
+
),
|
|
303
|
+
).then((lists) => {
|
|
304
|
+
const preferred = goodIps ? goodIps.get(hostname) : ''
|
|
305
|
+
const merged = [...new Set(lists.flat())]
|
|
306
|
+
if (preferred && merged.includes(preferred)) {
|
|
307
|
+
return [preferred, ...merged.filter((ip) => ip !== preferred)]
|
|
308
|
+
}
|
|
309
|
+
return merged
|
|
310
|
+
})
|
|
311
|
+
|
|
293
312
|
return (hostname, options, callback) => {
|
|
294
313
|
const wantAll = Boolean(options && options.all)
|
|
295
|
-
const settle = (
|
|
296
|
-
cache.set(hostname, {
|
|
297
|
-
if (wantAll) callback(null,
|
|
298
|
-
else callback(null,
|
|
314
|
+
const settle = (ips) => {
|
|
315
|
+
cache.set(hostname, { ips, at: Date.now() })
|
|
316
|
+
if (wantAll) callback(null, ips.map((address) => ({ address, family: net.isIP(address) })))
|
|
317
|
+
else callback(null, ips[0], net.isIP(ips[0]))
|
|
299
318
|
}
|
|
300
319
|
const cached = cache.get(hostname)
|
|
301
|
-
if (cached && cached.
|
|
302
|
-
|
|
303
|
-
else callback(null, cached.list[0], net.isIP(cached.list[0]))
|
|
320
|
+
if (cached && cached.ips.length && Date.now() - cached.at < ttlMs) {
|
|
321
|
+
settle(cached.ips)
|
|
304
322
|
return
|
|
305
323
|
}
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
if (!error6 && list6 && list6.length) return settle(list6)
|
|
310
|
-
callback(error4 || error6 || new Error('DNS_LOOKUP_FAILED'))
|
|
311
|
-
})
|
|
312
|
-
})
|
|
324
|
+
resolveAll(hostname)
|
|
325
|
+
.then((ips) => (ips.length ? settle(ips) : callback(new Error('DNS_LOOKUP_FAILED'))))
|
|
326
|
+
.catch((error) => callback(error))
|
|
313
327
|
}
|
|
314
328
|
}
|
|
315
329
|
|
|
@@ -324,7 +338,10 @@ function createTransport(cfg) {
|
|
|
324
338
|
}
|
|
325
339
|
let caPem
|
|
326
340
|
let caLoaded = false
|
|
327
|
-
|
|
341
|
+
// Remember which resolved address actually answered, so later requests to that
|
|
342
|
+
// host go straight to a working IP even when one resolver answers badly.
|
|
343
|
+
const goodIps = new Map()
|
|
344
|
+
const bypassLookup = makeBypassLookup(cfg.dnsServers, goodIps)
|
|
328
345
|
|
|
329
346
|
async function loadCa() {
|
|
330
347
|
if (caLoaded) return caPem
|
|
@@ -383,13 +400,21 @@ function createTransport(cfg) {
|
|
|
383
400
|
return routes
|
|
384
401
|
}
|
|
385
402
|
|
|
386
|
-
function rawRequest(options, body, timeoutMs, binary = false) {
|
|
403
|
+
function rawRequest(options, body, timeoutMs, binary = false, onAddress) {
|
|
387
404
|
return new Promise((resolve, reject) => {
|
|
388
405
|
const request = https.request(options, (response) => {
|
|
389
406
|
const chunks = []
|
|
390
407
|
response.on('data', (chunk) => chunks.push(chunk))
|
|
391
408
|
response.on('end', () => {
|
|
392
409
|
const joined = Buffer.concat(chunks)
|
|
410
|
+
if (onAddress) {
|
|
411
|
+
try {
|
|
412
|
+
const address = response.socket ? response.socket.remoteAddress : ''
|
|
413
|
+
if (address) onAddress(String(address).replace(/^::ffff:/, ''))
|
|
414
|
+
} catch {
|
|
415
|
+
/* best effort */
|
|
416
|
+
}
|
|
417
|
+
}
|
|
393
418
|
resolve({
|
|
394
419
|
status: response.statusCode || 0,
|
|
395
420
|
headers: response.headers,
|
|
@@ -485,6 +510,7 @@ function createTransport(cfg) {
|
|
|
485
510
|
options.body,
|
|
486
511
|
cfg.requestTimeoutMs,
|
|
487
512
|
options.binary === true,
|
|
513
|
+
(address) => goodIps.set(host, address),
|
|
488
514
|
)
|
|
489
515
|
}
|
|
490
516
|
|
|
@@ -1323,7 +1349,23 @@ function createGithub(ctx, cfg, transport) {
|
|
|
1323
1349
|
adminWrite: p.administration === 'write',
|
|
1324
1350
|
}
|
|
1325
1351
|
}
|
|
1326
|
-
if (auth.kind === '
|
|
1352
|
+
if (auth.kind === 'oauth') {
|
|
1353
|
+
// A GitHub App user token is still an App token: it can search code, but
|
|
1354
|
+
// GitHub exposes notifications only to OAuth-app/PAT tokens.
|
|
1355
|
+
return {
|
|
1356
|
+
repoRead: true,
|
|
1357
|
+
repoWrite: true,
|
|
1358
|
+
pullWrite: true,
|
|
1359
|
+
issueWrite: true,
|
|
1360
|
+
actionsWrite: true,
|
|
1361
|
+
workflowsWrite: true,
|
|
1362
|
+
adminWrite: true,
|
|
1363
|
+
notifications: false,
|
|
1364
|
+
codeSearch: true,
|
|
1365
|
+
userLevel: true,
|
|
1366
|
+
}
|
|
1367
|
+
}
|
|
1368
|
+
if (auth.kind === 'pat' || auth.kind === 'env') {
|
|
1327
1369
|
return {
|
|
1328
1370
|
repoRead: true,
|
|
1329
1371
|
repoWrite: true,
|
|
@@ -1622,6 +1664,103 @@ function createGithub(ctx, cfg, transport) {
|
|
|
1622
1664
|
return { ok: true, runId }
|
|
1623
1665
|
}
|
|
1624
1666
|
|
|
1667
|
+
async function listNotifications(options = {}) {
|
|
1668
|
+
const query = new URLSearchParams({ per_page: String(Math.min(100, options.limit || 30)) })
|
|
1669
|
+
if (options.all) query.set('all', 'true')
|
|
1670
|
+
if (options.participating) query.set('participating', 'true')
|
|
1671
|
+
const json = await call(`/notifications?${query.toString()}`)
|
|
1672
|
+
const items = (Array.isArray(json) ? json : []).map((item) => ({
|
|
1673
|
+
id: item.id,
|
|
1674
|
+
reason: item.reason,
|
|
1675
|
+
unread: item.unread,
|
|
1676
|
+
title: item.subject ? item.subject.title : '',
|
|
1677
|
+
type: item.subject ? item.subject.type : '',
|
|
1678
|
+
apiUrl: item.subject ? item.subject.url : '',
|
|
1679
|
+
htmlUrl: item.subject && item.subject.latest_comment_url ? item.subject.latest_comment_url.replace('/pulls/', '/pull/').replace(/\/comments\/.*$/, '') : '',
|
|
1680
|
+
repo: item.repository ? item.repository.full_name : '',
|
|
1681
|
+
updatedAt: item.updated_at,
|
|
1682
|
+
}))
|
|
1683
|
+
return { count: items.length, unread: items.filter((item) => item.unread).length, items }
|
|
1684
|
+
}
|
|
1685
|
+
|
|
1686
|
+
async function markNotificationsRead(options = {}) {
|
|
1687
|
+
if (options.all) {
|
|
1688
|
+
await call('/notifications', { method: 'PUT', body: { last_read_at: new Date().toISOString(), read: true } })
|
|
1689
|
+
return { ok: true, scope: 'all' }
|
|
1690
|
+
}
|
|
1691
|
+
const ids = Array.isArray(options.ids) ? options.ids : []
|
|
1692
|
+
if (!ids.length) throw new Error('需要 ids 或 all: true')
|
|
1693
|
+
for (const id of ids) {
|
|
1694
|
+
await call(`/notifications/threads/${encodeURIComponent(id)}`, { method: 'PATCH' })
|
|
1695
|
+
}
|
|
1696
|
+
return { ok: true, scope: 'ids', count: ids.length }
|
|
1697
|
+
}
|
|
1698
|
+
|
|
1699
|
+
async function searchCode(query, options = {}) {
|
|
1700
|
+
const text = String(query || '').trim()
|
|
1701
|
+
if (!text) throw new Error('搜索词不能为空')
|
|
1702
|
+
const scope = options.owner && options.name ? ` repo:${options.owner}/${options.name}` : ''
|
|
1703
|
+
const response = await call(`/search/code?q=${encodeURIComponent(text + scope)}&per_page=${Math.min(50, options.limit || 20)}`)
|
|
1704
|
+
const items = (response.items || []).map((item) => ({
|
|
1705
|
+
path: item.path,
|
|
1706
|
+
repo: item.repository ? item.repository.full_name : '',
|
|
1707
|
+
htmlUrl: item.html_url,
|
|
1708
|
+
sha: item.sha,
|
|
1709
|
+
}))
|
|
1710
|
+
return { total: response.total_count || items.length, returned: items.length, items }
|
|
1711
|
+
}
|
|
1712
|
+
|
|
1713
|
+
async function listReleases(owner, name) {
|
|
1714
|
+
const repo = repoPath(owner, name)
|
|
1715
|
+
const json = await call(`${repo}/releases?per_page=30`)
|
|
1716
|
+
return {
|
|
1717
|
+
items: (Array.isArray(json) ? json : []).map((item) => ({
|
|
1718
|
+
id: item.id,
|
|
1719
|
+
tag: item.tag_name,
|
|
1720
|
+
name: item.name || item.tag_name,
|
|
1721
|
+
draft: Boolean(item.draft),
|
|
1722
|
+
prerelease: Boolean(item.prerelease),
|
|
1723
|
+
publishedAt: item.published_at,
|
|
1724
|
+
htmlUrl: item.html_url,
|
|
1725
|
+
assets: (item.assets || []).map((asset) => ({ name: asset.name, size: asset.size, url: asset.browser_download_url })),
|
|
1726
|
+
})),
|
|
1727
|
+
}
|
|
1728
|
+
}
|
|
1729
|
+
|
|
1730
|
+
async function listCommits(owner, name, options = {}) {
|
|
1731
|
+
const repo = repoPath(owner, name)
|
|
1732
|
+
const query = new URLSearchParams({ per_page: String(Math.min(100, options.limit || 20)) })
|
|
1733
|
+
if (options.ref) query.set('sha', options.ref)
|
|
1734
|
+
const json = await call(`${repo}/commits?${query.toString()}`)
|
|
1735
|
+
return {
|
|
1736
|
+
items: (Array.isArray(json) ? json : []).map((item) => ({
|
|
1737
|
+
sha: item.sha,
|
|
1738
|
+
short: String(item.sha || '').slice(0, 7),
|
|
1739
|
+
message: item.commit ? String(item.commit.message || '').split('\n')[0] : '',
|
|
1740
|
+
author: item.commit && item.commit.author ? item.commit.author.name : '',
|
|
1741
|
+
date: item.commit && item.commit.author ? item.commit.author.date : '',
|
|
1742
|
+
htmlUrl: item.html_url,
|
|
1743
|
+
})),
|
|
1744
|
+
}
|
|
1745
|
+
}
|
|
1746
|
+
|
|
1747
|
+
async function compareRefs(owner, name, base, head) {
|
|
1748
|
+
const repo = repoPath(owner, name)
|
|
1749
|
+
if (!base || !head) throw new Error('需要 base 与 head')
|
|
1750
|
+
const json = await call(`${repo}/compare/${encodeURIComponent(base)}...${encodeURIComponent(head)}`)
|
|
1751
|
+
return {
|
|
1752
|
+
status: json.status,
|
|
1753
|
+
aheadBy: json.ahead_by,
|
|
1754
|
+
behindBy: json.behind_by,
|
|
1755
|
+
totalCommits: json.total_commits,
|
|
1756
|
+
commits: (json.commits || []).map((item) => ({
|
|
1757
|
+
short: String(item.sha || '').slice(0, 7),
|
|
1758
|
+
message: item.commit ? String(item.commit.message || '').split('\n')[0] : '',
|
|
1759
|
+
})),
|
|
1760
|
+
files: (json.files || []).map((file) => ({ path: file.filename, additions: file.additions, deletions: file.deletions })),
|
|
1761
|
+
}
|
|
1762
|
+
}
|
|
1763
|
+
|
|
1625
1764
|
async function pullDetail(owner, name, number) {
|
|
1626
1765
|
const repo = repoPath(owner, name)
|
|
1627
1766
|
const [pull, files] = await Promise.all([
|
|
@@ -1848,6 +1987,12 @@ function createGithub(ctx, cfg, transport) {
|
|
|
1848
1987
|
listWorkflows,
|
|
1849
1988
|
dispatchNamedWorkflow,
|
|
1850
1989
|
runLog,
|
|
1990
|
+
listNotifications,
|
|
1991
|
+
markNotificationsRead,
|
|
1992
|
+
searchCode,
|
|
1993
|
+
listReleases,
|
|
1994
|
+
listCommits,
|
|
1995
|
+
compareRefs,
|
|
1851
1996
|
}
|
|
1852
1997
|
}
|
|
1853
1998
|
|
|
@@ -3219,6 +3364,28 @@ export function apply(ctx, rawConfig) {
|
|
|
3219
3364
|
),
|
|
3220
3365
|
)
|
|
3221
3366
|
}
|
|
3367
|
+
if (route === 'POST /github-console/api/notifications') {
|
|
3368
|
+
return sendJson(response, 200, await gh.listNotifications(args))
|
|
3369
|
+
}
|
|
3370
|
+
if (route === 'POST /github-console/api/notifications/read') {
|
|
3371
|
+
return sendJson(
|
|
3372
|
+
response,
|
|
3373
|
+
200,
|
|
3374
|
+
await audited('notifications.read', args.all ? 'all' : (args.ids || []).join(','), () => gh.markNotificationsRead(args)),
|
|
3375
|
+
)
|
|
3376
|
+
}
|
|
3377
|
+
if (route === 'POST /github-console/api/search/code') {
|
|
3378
|
+
return sendJson(response, 200, await gh.searchCode(args.q, args))
|
|
3379
|
+
}
|
|
3380
|
+
if (route === 'POST /github-console/api/releases') {
|
|
3381
|
+
return sendJson(response, 200, await gh.listReleases(args.owner, args.name))
|
|
3382
|
+
}
|
|
3383
|
+
if (route === 'POST /github-console/api/commits') {
|
|
3384
|
+
return sendJson(response, 200, await gh.listCommits(args.owner, args.name, args))
|
|
3385
|
+
}
|
|
3386
|
+
if (route === 'POST /github-console/api/compare') {
|
|
3387
|
+
return sendJson(response, 200, await gh.compareRefs(args.owner, args.name, args.base, args.head))
|
|
3388
|
+
}
|
|
3222
3389
|
if (route === 'POST /github-console/api/pull/detail') {
|
|
3223
3390
|
return sendJson(response, 200, await gh.pullDetail(args.owner, args.name, args.number))
|
|
3224
3391
|
}
|
|
@@ -3456,6 +3623,60 @@ export function apply(ctx, rawConfig) {
|
|
|
3456
3623
|
}
|
|
3457
3624
|
return
|
|
3458
3625
|
}
|
|
3626
|
+
if (url.pathname === `${PREFIX}/device`) {
|
|
3627
|
+
// A plain HTML page: the panel may be stale or a popup blocked, but this
|
|
3628
|
+
// URL always shows the code and the verification link.
|
|
3629
|
+
try {
|
|
3630
|
+
const started = await gh.deviceStart()
|
|
3631
|
+
const checkUrl = `${PREFIX}/device/check?code=${encodeURIComponent(started.deviceCode)}`
|
|
3632
|
+
sendHtml(
|
|
3633
|
+
response,
|
|
3634
|
+
200,
|
|
3635
|
+
'GitHub 设备码授权',
|
|
3636
|
+
`在 GitHub 打开下面的页面,输入这个码并确认(${Math.round(started.expiresIn / 60)} 分钟内有效):`,
|
|
3637
|
+
`<p style="font:600 30px/1.3 ui-monospace,Consolas,monospace;letter-spacing:3px;margin:14px 0 6px">` +
|
|
3638
|
+
`${escapeHtml(started.userCode)}</p>` +
|
|
3639
|
+
`<p style="margin:0 0 16px"><a href="${escapeHtml(started.verificationUri)}" target="_blank" rel="noreferrer" ` +
|
|
3640
|
+
`style="display:inline-block;padding:9px 18px;border-radius:8px;background:#3E6FD8;color:#fff;text-decoration:none;font-size:14px">` +
|
|
3641
|
+
`打开 ${escapeHtml(started.verificationUri)}</a></p>` +
|
|
3642
|
+
`<p style="font-size:13px;color:#57606a">输入码并点 Authorize 之后,回到这里点下面的按钮确认:</p>` +
|
|
3643
|
+
`<p><a href="${escapeHtml(checkUrl)}" style="display:inline-block;padding:8px 16px;border:1px solid #3E6FD8;` +
|
|
3644
|
+
`border-radius:8px;color:#3E6FD8;text-decoration:none;font-size:13px">我已授权,检查状态</a></p>`,
|
|
3645
|
+
)
|
|
3646
|
+
} catch (failure) {
|
|
3647
|
+
const appRecord = await gh.readRecord(APP_CRED).catch(() => undefined)
|
|
3648
|
+
const appSlug = appRecord && appRecord.slug ? appRecord.slug : ''
|
|
3649
|
+
sendHtml(
|
|
3650
|
+
response,
|
|
3651
|
+
200,
|
|
3652
|
+
'拿不到设备码',
|
|
3653
|
+
errorMessage(failure),
|
|
3654
|
+
`<p style="font-size:13px;color:#57606a;line-height:1.8">· 若是「App 没有启用 Device Flow」:到 ` +
|
|
3655
|
+
`<a href="${escapeHtml(appSlug ? `https://github.com/settings/apps/${appSlug}` : 'https://github.com/settings/apps')}">` +
|
|
3656
|
+
`GitHub App 设置页</a> 勾选 Enable Device Flow → 底部 Save changes。<br>` +
|
|
3657
|
+
`· 若是网络错误:这台机器连 GitHub 不稳定,请在网络正常时重试。</p>`,
|
|
3658
|
+
)
|
|
3659
|
+
}
|
|
3660
|
+
return
|
|
3661
|
+
}
|
|
3662
|
+
if (url.pathname === `${PREFIX}/device/check`) {
|
|
3663
|
+
const code = url.searchParams.get('code') || ''
|
|
3664
|
+
try {
|
|
3665
|
+
const result = await gh.devicePoll(code)
|
|
3666
|
+
if (result.status === 'ok') {
|
|
3667
|
+
sendHtml(response, 200, '授权成功', '已保存用户令牌,并切换为「App 用户授权」连接。可以关闭此页面。')
|
|
3668
|
+
} else if (result.status === 'pending') {
|
|
3669
|
+
sendHtml(response, 200, '还在等待确认', 'GitHub 那边还没点 Authorize,稍等几秒再点一次检查。')
|
|
3670
|
+
} else if (result.status === 'expired') {
|
|
3671
|
+
sendHtml(response, 200, '设备码已过期', '重新打开 /github-console/device 生成新码。')
|
|
3672
|
+
} else {
|
|
3673
|
+
sendHtml(response, 200, '授权被拒绝', '你在 GitHub 上取消了授权。')
|
|
3674
|
+
}
|
|
3675
|
+
} catch (failure) {
|
|
3676
|
+
sendHtml(response, 200, '检查失败', errorMessage(failure))
|
|
3677
|
+
}
|
|
3678
|
+
return
|
|
3679
|
+
}
|
|
3459
3680
|
if (url.pathname === `${PREFIX}/icon.svg`) {
|
|
3460
3681
|
// The index references ../icon.svg relative to /github-console/market/index.json.
|
|
3461
3682
|
const svg = await fs.readFile(path.join(PLUGIN_DIR, 'icon.svg')).catch(() => null)
|
|
@@ -4360,6 +4581,118 @@ export function apply(ctx, rawConfig) {
|
|
|
4360
4581
|
},
|
|
4361
4582
|
})
|
|
4362
4583
|
|
|
4584
|
+
register({
|
|
4585
|
+
name: 'gh_notifications',
|
|
4586
|
+
description:
|
|
4587
|
+
'List GitHub notifications (mentions, review requests, CI failures, assigned issues). Requires a user connection (App user authorization, PAT or environment token): an installation token cannot read notifications. Set all=true for read threads too.',
|
|
4588
|
+
parameters: {
|
|
4589
|
+
type: 'object',
|
|
4590
|
+
properties: {
|
|
4591
|
+
all: { type: 'boolean', description: 'Include already-read threads' },
|
|
4592
|
+
participating: { type: 'boolean', description: 'Only threads you participate in' },
|
|
4593
|
+
limit: { type: 'integer', minimum: 1, maximum: 100 },
|
|
4594
|
+
},
|
|
4595
|
+
additionalProperties: false,
|
|
4596
|
+
},
|
|
4597
|
+
output: { schema: { type: 'object' }, render: (args, value) => textOf(value) },
|
|
4598
|
+
async execute(args) {
|
|
4599
|
+
return gh.listNotifications(args)
|
|
4600
|
+
},
|
|
4601
|
+
})
|
|
4602
|
+
|
|
4603
|
+
register({
|
|
4604
|
+
name: 'gh_notifications_read',
|
|
4605
|
+
description: 'Mark notifications read: pass ids for selected threads, or all=true to mark everything read. Writes are audited.',
|
|
4606
|
+
parameters: {
|
|
4607
|
+
type: 'object',
|
|
4608
|
+
properties: {
|
|
4609
|
+
ids: { type: 'array', items: { type: 'string' }, description: 'Notification thread ids' },
|
|
4610
|
+
all: { type: 'boolean', description: 'Mark every thread read' },
|
|
4611
|
+
},
|
|
4612
|
+
additionalProperties: false,
|
|
4613
|
+
},
|
|
4614
|
+
output: { schema: { type: 'object' }, render: (args, value) => textOf(value) },
|
|
4615
|
+
async execute(args) {
|
|
4616
|
+
return audited('notifications.read', args.all ? 'all' : (args.ids || []).join(','), () => gh.markNotificationsRead(args))
|
|
4617
|
+
},
|
|
4618
|
+
})
|
|
4619
|
+
|
|
4620
|
+
register({
|
|
4621
|
+
name: 'gh_code_search',
|
|
4622
|
+
description:
|
|
4623
|
+
'Search code across GitHub or inside one repository. Requires a user connection (an installation token cannot use the code search API). Rate limited to about 10 requests per minute.',
|
|
4624
|
+
parameters: {
|
|
4625
|
+
type: 'object',
|
|
4626
|
+
properties: {
|
|
4627
|
+
q: { type: 'string', description: 'Search terms, GitHub code search syntax' },
|
|
4628
|
+
owner: { type: 'string', description: 'Restrict to this owner' },
|
|
4629
|
+
name: { type: 'string', description: 'Restrict to this repository' },
|
|
4630
|
+
limit: { type: 'integer', minimum: 1, maximum: 50 },
|
|
4631
|
+
},
|
|
4632
|
+
required: ['q'],
|
|
4633
|
+
additionalProperties: false,
|
|
4634
|
+
},
|
|
4635
|
+
output: { schema: { type: 'object' }, render: (args, value) => textOf(value) },
|
|
4636
|
+
async execute(args) {
|
|
4637
|
+
return gh.searchCode(args.q, args)
|
|
4638
|
+
},
|
|
4639
|
+
})
|
|
4640
|
+
|
|
4641
|
+
register({
|
|
4642
|
+
name: 'gh_releases',
|
|
4643
|
+
description: 'List repository releases with their assets and download URLs.',
|
|
4644
|
+
parameters: {
|
|
4645
|
+
type: 'object',
|
|
4646
|
+
properties: { owner: { type: 'string' }, name: { type: 'string' } },
|
|
4647
|
+
required: ['owner', 'name'],
|
|
4648
|
+
additionalProperties: false,
|
|
4649
|
+
},
|
|
4650
|
+
output: { schema: { type: 'object' }, render: (args, value) => textOf(value) },
|
|
4651
|
+
async execute(args) {
|
|
4652
|
+
return gh.listReleases(args.owner, args.name)
|
|
4653
|
+
},
|
|
4654
|
+
})
|
|
4655
|
+
|
|
4656
|
+
register({
|
|
4657
|
+
name: 'gh_commits',
|
|
4658
|
+
description: 'List recent commits of a branch or ref with author, date and message subject.',
|
|
4659
|
+
parameters: {
|
|
4660
|
+
type: 'object',
|
|
4661
|
+
properties: {
|
|
4662
|
+
owner: { type: 'string' },
|
|
4663
|
+
name: { type: 'string' },
|
|
4664
|
+
ref: { type: 'string', description: 'Branch, tag or sha; default the repository default branch' },
|
|
4665
|
+
limit: { type: 'integer', minimum: 1, maximum: 100 },
|
|
4666
|
+
},
|
|
4667
|
+
required: ['owner', 'name'],
|
|
4668
|
+
additionalProperties: false,
|
|
4669
|
+
},
|
|
4670
|
+
output: { schema: { type: 'object' }, render: (args, value) => textOf(value) },
|
|
4671
|
+
async execute(args) {
|
|
4672
|
+
return gh.listCommits(args.owner, args.name, args)
|
|
4673
|
+
},
|
|
4674
|
+
})
|
|
4675
|
+
|
|
4676
|
+
register({
|
|
4677
|
+
name: 'gh_compare',
|
|
4678
|
+
description: 'Compare two refs: ahead/behind counts, commits and changed files. Use it to review a branch before opening a pull request.',
|
|
4679
|
+
parameters: {
|
|
4680
|
+
type: 'object',
|
|
4681
|
+
properties: {
|
|
4682
|
+
owner: { type: 'string' },
|
|
4683
|
+
name: { type: 'string' },
|
|
4684
|
+
base: { type: 'string', description: 'Base ref, for example main' },
|
|
4685
|
+
head: { type: 'string', description: 'Head ref, for example feature/x' },
|
|
4686
|
+
},
|
|
4687
|
+
required: ['owner', 'name', 'base', 'head'],
|
|
4688
|
+
additionalProperties: false,
|
|
4689
|
+
},
|
|
4690
|
+
output: { schema: { type: 'object' }, render: (args, value) => textOf(value) },
|
|
4691
|
+
async execute(args) {
|
|
4692
|
+
return gh.compareRefs(args.owner, args.name, args.base, args.head)
|
|
4693
|
+
},
|
|
4694
|
+
})
|
|
4695
|
+
|
|
4363
4696
|
register({
|
|
4364
4697
|
name: 'plugin_publish_status',
|
|
4365
4698
|
description: 'Read a publish job by id, including each step state and detail.',
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-github-console",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"description": "GitHub console for DeepSeek Harness: GitHub App sign-in, repository browsing, issues/pulls/CI, plugin publishing with market checks, npm release via GitHub Actions, and a self-hosted market index",
|