From 7b2b5871ede454610c6b06ab282d52b2273a54be Mon Sep 17 00:00:00 2001 From: y574444354 <574444354@qq.com> Date: Tue, 12 May 2026 12:23:50 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BD=BF=E7=94=A8=20HTTPS=20+=20gh=20to?= =?UTF-8?q?ken=20=E6=9B=BF=E4=BB=A3=20SSH=20=E5=85=8B=E9=9A=86=20review=20?= =?UTF-8?q?=E4=BB=93=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 将 generate-review-builtin.ts 的 CLONE_URL 从 SSH (git@github.com:) 改为 HTTPS,并通过 gh auth token 或环境变量获取认证令牌, 解决 SSH key 未配置时无法克隆私有仓库的问题。 --- scripts/dev.ts | 2 +- scripts/generate-review-builtin.ts | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/scripts/dev.ts b/scripts/dev.ts index a17ce4a11..5366534f9 100644 --- a/scripts/dev.ts +++ b/scripts/dev.ts @@ -54,7 +54,7 @@ const bunCmd = process.execPath; // Generate review builtin files before dev launch console.log('[dev] Generating review builtin files...'); const genResult = Bun.spawnSync(['bun', 'run', 'scripts/generate-review-builtin.ts'], { - stdio: 'inherit', + stdio: ["inherit", "inherit", "inherit"], cwd: projectRoot, }); if (!genResult.success) { diff --git a/scripts/generate-review-builtin.ts b/scripts/generate-review-builtin.ts index 071554091..0af742575 100644 --- a/scripts/generate-review-builtin.ts +++ b/scripts/generate-review-builtin.ts @@ -36,7 +36,21 @@ type IndexJson = { const REPO = 'zgsm-ai/costrict-review' const BRANCH = 'main' -const CLONE_URL = `git@github.com:${REPO}.git` +const CLONE_URL = getCloneUrl() + +function getCloneUrl(): string { + // Try gh CLI token first, then env vars, fall back to public HTTPS + const ghToken = (() => { + try { + return spawnSync('gh', ['auth', 'token'], { encoding: 'utf-8' }).stdout?.trim() || '' + } catch { return '' } + })() + const token = ghToken || process.env.GH_TOKEN || process.env.GITHUB_TOKEN || '' + if (token) { + return `https://x-access-token:${token}@github.com/${REPO}.git` + } + return `https://github.com/${REPO}.git` +} function git(...args: string[]): { ok: boolean; stdout: string; stderr: string } { const result = spawnSync('git', args, { encoding: 'utf-8' })