dsh-github-console 0.6.3 → 0.7.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -1
- package/cordis.patch.yml +1 -0
- package/index.js +168 -14
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -110,7 +110,7 @@ manifest 的三步必须在 **1 小时**内完成,`state` 一次性、5 分钟
|
|
|
110
110
|
|
|
111
111
|
1. **体检** —— `package.json`(容忍 BOM)、`dsh.bundle.patch`、入口文件、README/LICENSE/.gitignore、疑似密钥正则、本机绝对路径、npm 同名同版本、**敏感文件名拦截**(`.env*`、`.npmrc`、`*.pem/key/p12` 等直接 block)、**分支保护探测**
|
|
112
112
|
2. **仓库** —— 确认仓库可访问(不存在时给出 `github.com/new?name=…` 链接)
|
|
113
|
-
3. **推送** —— 收集目录内文件(跳过 `node_modules`、`.git`),经 blobs → tree → commit → ref
|
|
113
|
+
3. **推送** —— 收集目录内文件(跳过 `node_modules`、`.git`),经 blobs → tree → commit → ref 提交到目标分支。**目标分支有保护时自动改走 PR**:把改动提交到 `dsh-publish/v<version>-<ts>` 临时分支 → 开 PR → squash 合并 → 合并成功后删除临时分支(并顺带清理历史遗留的已合并 `dsh-publish/*`)。仓库要求评审时不会假合并,而是把 PR 链接写进推送步骤、**跳过 Release**(tag 不能指向没进主干的代码)。配置项 `publishMode`:`auto`(默认,看分支保护)/ `direct`(总是直推)/ `pr`(总走 PR)。:
|
|
114
114
|
- **删除同步**:远端有、本地没有的文件会被删除,但 `.github/workflows/*` 与 `.github/dependabot.yml` 属受保护路径,永不删除
|
|
115
115
|
- **执行位**:本地可执行文件按 `100755` 提交,其余 `100644`;提交后回读 tree 校验,结果写进推送步骤详情
|
|
116
116
|
- **文件数上限 300**:达到上限即 block(不再静默截断),超大文件会计入「跳过」并在详情里显示
|
|
@@ -129,6 +129,7 @@ npm 与市场索引的探测走的是插件自己的传输层(同一个代理
|
|
|
129
129
|
| `baseUrl` | `https://api.github.com` | GHES 可改这里 |
|
|
130
130
|
| `appName` | 空 | App 名;留空用 `DSH GitHub Console <随机后缀>` |
|
|
131
131
|
| `publishBranch` | `main` | 发布目标分支 |
|
|
132
|
+
| `publishMode` | `auto` | `auto` 按分支保护决定直推还是 PR;`direct` 总是直推;`pr` 总走 PR |
|
|
132
133
|
| `topic` | `dsh-plugin` | 发布时合并的 topic |
|
|
133
134
|
| `marketIndexUrls` | `[]` | format-1 JSON 索引地址,逐个探测 |
|
|
134
135
|
| `maxPushBytes` | 8388608 | 单次推送的文件总字节上限 |
|
package/cordis.patch.yml
CHANGED
package/index.js
CHANGED
|
@@ -25,7 +25,7 @@ import { promises as dnsPromises, Resolver } from 'node:dns'
|
|
|
25
25
|
import { capabilityFor, isDeniedFile, isProtectedRemotePath, marketIndexDocument, unzipEntries } from './lib/pure.mjs'
|
|
26
26
|
import { collectFiles } from './lib/collect.mjs'
|
|
27
27
|
|
|
28
|
-
const PLUGIN_VERSION = '0.
|
|
28
|
+
const PLUGIN_VERSION = '0.7.3'
|
|
29
29
|
const APP_CRED = 'github-console/app'
|
|
30
30
|
const INSTALL_CRED = 'github-console/install'
|
|
31
31
|
const BRIDGE_CRED = 'github-console/bridge'
|
|
@@ -205,7 +205,10 @@ function normalizeConfig(raw) {
|
|
|
205
205
|
: 'market/index.json',
|
|
206
206
|
npmUser: typeof config.npmUser === 'string' ? config.npmUser.trim() : '',
|
|
207
207
|
// Connection selection: 'auto' prefers App, then PAT, then the environment.
|
|
208
|
-
authMode: ['auto', 'app', 'pat', 'env'].includes(config.authMode) ? config.authMode : 'auto',
|
|
208
|
+
authMode: ['auto', 'app', 'oauth', 'pat', 'env'].includes(config.authMode) ? config.authMode : 'auto',
|
|
209
|
+
// Publishing path: 'auto' switches to a pull request when the branch is
|
|
210
|
+
// protected, 'direct' always pushes, 'pr' always goes through a PR.
|
|
211
|
+
publishMode: ['auto', 'direct', 'pr'].includes(config.publishMode) ? config.publishMode : 'auto',
|
|
209
212
|
patEnvName: typeof config.patEnvName === 'string' && config.patEnvName ? config.patEnvName : 'GITHUB_TOKEN',
|
|
210
213
|
readOnly: config.readOnly === true,
|
|
211
214
|
}
|
|
@@ -2408,8 +2411,110 @@ async function pushFiles(gh, owner, name, branch, files, message) {
|
|
|
2408
2411
|
}
|
|
2409
2412
|
}
|
|
2410
2413
|
|
|
2411
|
-
|
|
2412
|
-
|
|
2414
|
+
/** Whether direct pushes to this branch are refused by a protection rule. */
|
|
2415
|
+
async function branchProtection(gh, owner, repo, branch) {
|
|
2416
|
+
try {
|
|
2417
|
+
const body = await gh.call(`/repos/${encodeURIComponent(owner)}/${encodeURIComponent(repo)}/branches/${encodeURIComponent(branch)}/protection`)
|
|
2418
|
+
return { protected: true, body }
|
|
2419
|
+
} catch (error) {
|
|
2420
|
+
if (error && error.status === 404) return { protected: false }
|
|
2421
|
+
return { protected: null, error: errorMessage(error) }
|
|
2422
|
+
}
|
|
2423
|
+
}
|
|
2424
|
+
|
|
2425
|
+
/**
|
|
2426
|
+
* Publishing onto a protected branch: commit to a topic branch, open a pull
|
|
2427
|
+
* request and squash-merge it. When the repository requires reviews the merge is
|
|
2428
|
+
* refused and the caller reports the PR instead of pretending it shipped.
|
|
2429
|
+
*/
|
|
2430
|
+
async function pushViaPullRequest(gh, owner, repo, branch, files, message, options = {}) {
|
|
2431
|
+
const base = `/repos/${encodeURIComponent(owner)}/${encodeURIComponent(repo)}`
|
|
2432
|
+
const ref = await gh.call(`${base}/git/ref/heads/${encodeURIComponent(branch)}`)
|
|
2433
|
+
const baseCommit = ref && ref.object ? ref.object.sha : ''
|
|
2434
|
+
if (!baseCommit) throw new Error(`读不到 ${branch} 的最新提交`)
|
|
2435
|
+
const head = `dsh-publish/v${options.version || 'next'}-${Date.now().toString(36)}`
|
|
2436
|
+
|
|
2437
|
+
const blobs = await Promise.all(
|
|
2438
|
+
files.map(async (file) => {
|
|
2439
|
+
const blob = await gh.call(`${base}/git/blobs`, { method: 'POST', body: { content: file.content.toString('base64'), encoding: 'base64' } })
|
|
2440
|
+
return blob.sha
|
|
2441
|
+
}),
|
|
2442
|
+
)
|
|
2443
|
+
const entries = files.map((file, index) => ({ path: file.path, mode: file.mode || '100644', type: 'blob', sha: blobs[index] }))
|
|
2444
|
+
let deleted = 0
|
|
2445
|
+
const remote = await gh.call(`${base}/git/trees/${baseCommit}?recursive=1`).catch(() => null)
|
|
2446
|
+
if (remote && Array.isArray(remote.tree)) {
|
|
2447
|
+
const local = new Set(files.map((file) => file.path))
|
|
2448
|
+
const stale = remote.tree
|
|
2449
|
+
.filter((item) => item.type === 'blob' && !local.has(item.path) && !isDeniedFile(item.path) && !isProtectedRemotePath(item.path))
|
|
2450
|
+
.map((item) => item.path)
|
|
2451
|
+
deleted = stale.length
|
|
2452
|
+
for (const filePath of stale) entries.push({ path: filePath, mode: '100644', type: 'blob', sha: null })
|
|
2453
|
+
}
|
|
2454
|
+
const tree = await gh.call(`${base}/git/trees`, { method: 'POST', body: { tree: entries, base_tree: baseCommit } })
|
|
2455
|
+
const commit = await gh.call(`${base}/git/commits`, { method: 'POST', body: { message, tree: tree.sha, parents: [baseCommit] } })
|
|
2456
|
+
await gh.call(`${base}/git/refs`, { method: 'POST', body: { ref: `refs/heads/${head}`, sha: commit.sha } })
|
|
2457
|
+
|
|
2458
|
+
const open = await gh
|
|
2459
|
+
.call(`${base}/pulls?state=open&head=${encodeURIComponent(`${owner}:${head}`)}&per_page=1`)
|
|
2460
|
+
.catch(() => [])
|
|
2461
|
+
let pull = Array.isArray(open) && open.length ? open[0] : null
|
|
2462
|
+
if (!pull) {
|
|
2463
|
+
pull = await gh.call(`${base}/pulls`, {
|
|
2464
|
+
method: 'POST',
|
|
2465
|
+
body: {
|
|
2466
|
+
title: options.title || message,
|
|
2467
|
+
head,
|
|
2468
|
+
base: branch,
|
|
2469
|
+
body: `${options.notes ? `${options.notes}\n\n` : ''}由 DSH GitHub 控制台自动打开:\`${branch}\` 有分支保护,改为 PR 合并。`,
|
|
2470
|
+
},
|
|
2471
|
+
})
|
|
2472
|
+
}
|
|
2473
|
+
|
|
2474
|
+
let merged = false
|
|
2475
|
+
let mergeNote = ''
|
|
2476
|
+
try {
|
|
2477
|
+
const result = await gh.call(`${base}/pulls/${pull.number}/merge`, {
|
|
2478
|
+
method: 'PUT',
|
|
2479
|
+
body: { merge_method: 'squash', commit_title: `${options.title || message} (#${pull.number})` },
|
|
2480
|
+
})
|
|
2481
|
+
merged = Boolean(result && result.merged)
|
|
2482
|
+
if (!merged) mergeNote = (result && result.message) || ''
|
|
2483
|
+
} catch (error) {
|
|
2484
|
+
mergeNote = errorMessage(error)
|
|
2485
|
+
}
|
|
2486
|
+
if (merged) {
|
|
2487
|
+
// The topic branch served its purpose; leaving one per release clutters it.
|
|
2488
|
+
await gh.call(`${base}/git/refs/heads/${encodeURIComponent(head)}`, { method: 'DELETE' }).catch(() => {})
|
|
2489
|
+
// Also drop topic branches from earlier runs whose pull request is merged.
|
|
2490
|
+
// A squash merge makes the branch's commit a non-ancestor of the base, so
|
|
2491
|
+
// `compare` reports "diverged"; the pull request is the reliable signal.
|
|
2492
|
+
const stale = await gh.call(`${base}/git/matching-refs/heads/dsh-publish/`).catch(() => [])
|
|
2493
|
+
for (const item of Array.isArray(stale) ? stale : []) {
|
|
2494
|
+
const name = String(item.ref || '').replace('refs/heads/', '')
|
|
2495
|
+
if (!name) continue
|
|
2496
|
+
const pulls = await gh
|
|
2497
|
+
.call(`${base}/pulls?state=all&per_page=1&head=${encodeURIComponent(`${owner}:${name}`)}`)
|
|
2498
|
+
.catch(() => [])
|
|
2499
|
+
const pull = Array.isArray(pulls) && pulls.length ? pulls[0] : null
|
|
2500
|
+
if (pull && pull.merged_at) {
|
|
2501
|
+
await gh.call(`${base}/git/refs/heads/${encodeURIComponent(name)}`, { method: 'DELETE' }).catch(() => {})
|
|
2502
|
+
}
|
|
2503
|
+
}
|
|
2504
|
+
}
|
|
2505
|
+
return {
|
|
2506
|
+
head,
|
|
2507
|
+
prNumber: pull.number,
|
|
2508
|
+
prUrl: pull.html_url,
|
|
2509
|
+
merged,
|
|
2510
|
+
mergeNote,
|
|
2511
|
+
commit: merged && pull.merge_commit_sha ? pull.merge_commit_sha : commit.sha,
|
|
2512
|
+
files: files.length,
|
|
2513
|
+
deleted,
|
|
2514
|
+
}
|
|
2515
|
+
}
|
|
2516
|
+
|
|
2517
|
+
async function mergeTopics(gh, owner, name, topics) { const repo = `/repos/${encodeURIComponent(owner)}/${encodeURIComponent(name)}`
|
|
2413
2518
|
const current = await gh.call(`${repo}/topics`, { headers: { Accept: 'application/vnd.github+json' } })
|
|
2414
2519
|
const existing = Array.isArray(current.names) ? current.names : []
|
|
2415
2520
|
const merged = Array.from(new Set([...existing, ...topics].map((item) => String(item).toLowerCase())))
|
|
@@ -2991,6 +3096,10 @@ function createJobStore() {
|
|
|
2991
3096
|
finishedAt: null,
|
|
2992
3097
|
ok: null,
|
|
2993
3098
|
target: meta,
|
|
3099
|
+
commit: null,
|
|
3100
|
+
releaseUrl: null,
|
|
3101
|
+
prUrl: null,
|
|
3102
|
+
market: null,
|
|
2994
3103
|
steps: [
|
|
2995
3104
|
{ id: 'preflight', title: '体检', state: 'pending', detail: '' },
|
|
2996
3105
|
{ id: 'repo', title: '确认仓库', state: 'pending', detail: '' },
|
|
@@ -3053,18 +3162,44 @@ async function runPublish({ job, gh, cfg, dir, owner, repo, version, notes, opts
|
|
|
3053
3162
|
}
|
|
3054
3163
|
|
|
3055
3164
|
const branch = opts.branch || cfg.publishBranch
|
|
3165
|
+
const mode = cfg.publishMode || 'auto'
|
|
3166
|
+
let pushed = null
|
|
3167
|
+
let pendingPull = null
|
|
3056
3168
|
try {
|
|
3057
3169
|
const collected = await collectFiles(path.resolve(dir), cfg.maxPushBytes)
|
|
3058
|
-
|
|
3059
|
-
|
|
3060
|
-
|
|
3061
|
-
|
|
3062
|
-
(
|
|
3063
|
-
|
|
3064
|
-
|
|
3065
|
-
|
|
3066
|
-
|
|
3067
|
-
|
|
3170
|
+
let protectedBranch = mode === 'pr'
|
|
3171
|
+
if (mode === 'auto') {
|
|
3172
|
+
const protection = await branchProtection(gh, owner, repo, branch)
|
|
3173
|
+
protectedBranch = protection.protected === true
|
|
3174
|
+
if (protectedBranch) {
|
|
3175
|
+
step(job, 'push').detail = `${branch} 有分支保护,改走 PR 流程`
|
|
3176
|
+
}
|
|
3177
|
+
}
|
|
3178
|
+
if (protectedBranch) {
|
|
3179
|
+
const viaPr = await pushViaPullRequest(gh, owner, repo, branch, collected.files, opts.message || `chore(release): v${semver}`, {
|
|
3180
|
+
version: semver,
|
|
3181
|
+
notes,
|
|
3182
|
+
title: opts.title || `chore(release): v${semver}`,
|
|
3183
|
+
})
|
|
3184
|
+
step(job, 'push').state = 'done'
|
|
3185
|
+
step(job, 'push').detail =
|
|
3186
|
+
`${viaPr.files} 个文件 → PR #${viaPr.prNumber}(${viaPr.merged ? '已自动合并' : '等待评审'})` +
|
|
3187
|
+
(viaPr.deleted ? `,删除远端 ${viaPr.deleted} 个过期文件` : '')
|
|
3188
|
+
job.commit = viaPr.commit
|
|
3189
|
+
job.prUrl = viaPr.prUrl
|
|
3190
|
+
if (!viaPr.merged) pendingPull = viaPr
|
|
3191
|
+
} else {
|
|
3192
|
+
pushed = await pushFiles(gh, owner, repo, branch, collected.files, opts.message || `chore(release): v${semver}`)
|
|
3193
|
+
step(job, 'push').state = 'done'
|
|
3194
|
+
step(job, 'push').detail =
|
|
3195
|
+
`${pushed.files} 个文件 → ${branch} @ ${pushed.commit.slice(0, 7)}` +
|
|
3196
|
+
(pushed.deleted ? `,删除远端 ${pushed.deleted} 个过期文件` : '') +
|
|
3197
|
+
(pushed.modeChecked
|
|
3198
|
+
? `,执行位已校验 ${pushed.modeChecked} 个${pushed.modeMismatch ? `(其中 ${pushed.modeMismatch} 个仍是 100644)` : ''}`
|
|
3199
|
+
: '') +
|
|
3200
|
+
(pushed.firstCommit ? '(仓库原本为空,这是首个提交)' : '')
|
|
3201
|
+
job.commit = pushed.commit
|
|
3202
|
+
}
|
|
3068
3203
|
} catch (error) {
|
|
3069
3204
|
step(job, 'push').state = 'failed'
|
|
3070
3205
|
step(job, 'push').detail = errorMessage(error)
|
|
@@ -3082,6 +3217,25 @@ async function runPublish({ job, gh, cfg, dir, owner, repo, version, notes, opts
|
|
|
3082
3217
|
step(job, 'topics').detail = `已跳过(可选权限 Administration: write):${errorMessage(error)}`
|
|
3083
3218
|
}
|
|
3084
3219
|
|
|
3220
|
+
if (pendingPull) {
|
|
3221
|
+
// The commit only exists on the topic branch: a tag now would point at code
|
|
3222
|
+
// that is not on the publish branch yet, so the release waits for the merge.
|
|
3223
|
+
step(job, 'release').state = 'done'
|
|
3224
|
+
step(job, 'release').detail = `等 PR #${pendingPull.prNumber} 合并后再发 Release:${pendingPull.prUrl}`
|
|
3225
|
+
job.releaseUrl = null
|
|
3226
|
+
try {
|
|
3227
|
+
const probe = await probeMarket({ name: pkgName, owner, repo, version: semver }, gh, cfg)
|
|
3228
|
+
step(job, 'market').state = 'done'
|
|
3229
|
+
step(job, 'market').detail = `(PR 未合并,暂不统计)${probe.results.map((item) => `${item.id}:${item.state}`).join(' · ')}`
|
|
3230
|
+
job.market = probe
|
|
3231
|
+
} catch (error) {
|
|
3232
|
+
step(job, 'market').state = 'failed'
|
|
3233
|
+
step(job, 'market').detail = errorMessage(error)
|
|
3234
|
+
}
|
|
3235
|
+
const failedPending = job.steps.some((item) => item.state === 'failed')
|
|
3236
|
+
return finish(!failedPending)
|
|
3237
|
+
}
|
|
3238
|
+
|
|
3085
3239
|
try {
|
|
3086
3240
|
const release = await createRelease(gh, owner, repo, semver, branch, notes)
|
|
3087
3241
|
step(job, 'release').state = 'done'
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-github-console",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.3",
|
|
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",
|