diff --git a/app/git.js b/app/git.js index 1f71689..8cda213 100644 --- a/app/git.js +++ b/app/git.js @@ -109,8 +109,12 @@ export async function commitAndPush(workspace, repoDir, _spawnSync = spawnSync, const out = run(['commit', '-m', 'chore: update ai-review findings [skip ci]'], repoDir); const commitHash = out.match(/\[.+ ([a-f0-9]+)\]/)?.[1] || 'unknown'; - run(['push', remoteUrl, PR_HEAD_BRANCH], repoDir, credEnv); - console.log(` ✅ persisted findings commit=${commitHash} push=${PR_HEAD_BRANCH}`); + try { + run(['push', remoteUrl, PR_HEAD_BRANCH], repoDir, credEnv); + console.log(` ✅ persisted findings commit=${commitHash} push=${PR_HEAD_BRANCH}`); + } catch (pushErr) { + console.log(` ⚠️ Step7 commit 成功但 push 失敗: commit=${commitHash} push=${PR_HEAD_BRANCH} error=${pushErr.message}`); + } }); } catch (e) { console.log(` ⚠️ Runner failed: commit/push 失敗: ${e.message}`); diff --git a/app/git.test.js b/app/git.test.js index a86cd34..0786aea 100644 --- a/app/git.test.js +++ b/app/git.test.js @@ -150,6 +150,32 @@ describe('commitAndPush', () => { const failSpawn = () => ({ status: 1, stdout: '', stderr: 'fatal: error', error: null }); await assert.doesNotReject(() => commitAndPush(workspace, path.join(workspace, 'repo'), failSpawn, sourceRoot)); }); + + it('logs push failures separately from commit failures', async () => { + const repoDir = path.join(workspace, 'repo'); + fs.mkdirSync(path.join(workspace, '.gitea/ai-review'), { recursive: true }); + fs.writeFileSync(path.join(workspace, '.gitea/ai-review/findings.json'), '[]\n'); + fs.writeFileSync(path.join(workspace, '.gitea/ai-review/exclusions.json'), '[]\n'); + fs.mkdirSync(path.join(repoDir, '.gitea/ai-review'), { recursive: true }); + fs.writeFileSync(path.join(repoDir, '.gitea/ai-review/findings.json'), '[]\n'); + fs.writeFileSync(path.join(repoDir, '.gitea/ai-review/exclusions.json'), '[]\n'); + + const spawn = makeSpawn({ + push: () => ({ status: 1, stdout: '', stderr: 'remote: error: pre-receive hook declined', error: null }), + }); + const logs = []; + const originalLog = console.log; + console.log = (...args) => { logs.push(args.join(' ')); }; + + try { + await commitAndPush(workspace, repoDir, spawn, sourceRoot); + } finally { + console.log = originalLog; + } + + assert.ok(logs.some(line => line.includes('Step7 commit 成功但 push 失敗'))); + assert.ok(logs.some(line => line.includes('pre-receive hook declined'))); + }); }); describe('cloneRepo', () => {