import fs from 'fs'; import path from 'path'; import { commitFile } from './gitea.js'; import { FINDINGS_PATH } from './config.js'; /** * 透過 Gitea API 將 findings.json push 到來源分支(不需要 git binary) */ export async function commitAndPush(workspace) { try { const fullPath = path.join(workspace, FINDINGS_PATH); const content = fs.readFileSync(fullPath, 'utf8'); console.log(` [debug] FINDINGS_PATH=${FINDINGS_PATH} branch=${process.env.PR_HEAD_BRANCH} token=${process.env.GITEA_TOKEN ? '***' : 'EMPTY'}`); const result = await commitFile( FINDINGS_PATH, content, 'chore: update ai-review findings [skip ci]' ); const commitHash = result.commit?.sha?.slice(0, 7) || 'unknown'; console.log(` ✅ persisted findings commit=${commitHash} push=${process.env.PR_HEAD_BRANCH}`); } catch (e) { const detail = e.response?.data ? JSON.stringify(e.response.data) : e.message; console.log(` ⚠️ Runner failed: commit/push 失敗: ${e.response?.status || ''} ${detail}`); } }