From 69624a542e37ca1df37a27203da581d262c67d63 Mon Sep 17 00:00:00 2001 From: Jeffery Date: Mon, 11 May 2026 10:50:16 +0000 Subject: [PATCH] fix: refactor commitAndPush function to improve clarity and maintainability --- app/git.js | 51 ++++++++++++++++++++++++++++++++++----------------- 1 file changed, 34 insertions(+), 17 deletions(-) diff --git a/app/git.js b/app/git.js index 87ec0c9..e3e0a2c 100644 --- a/app/git.js +++ b/app/git.js @@ -15,24 +15,41 @@ export async function commitAndPush(workspace) { .replace('https://', `https://${GITEA_TOKEN}@`) .replace('http://', `http://${GITEA_TOKEN}@`) + `/${GITEA_REPOSITORY}.git`; - try { - git(['config', 'user.email', 'ai-review[bot]@gitea'], repoDir); - git(['config', 'user.name', 'AI Review Bot'], repoDir); - git(['fetch', 'origin', PR_HEAD_BRANCH], repoDir); - git(['checkout', PR_HEAD_BRANCH], repoDir); - git(['add', FINDINGS_PATH], repoDir); + // try { + // git(['config', 'user.email', 'ai-review[bot]@gitea'], repoDir); + // git(['config', 'user.name', 'AI Review Bot'], repoDir); + // git(['fetch', 'origin', PR_HEAD_BRANCH], repoDir); + // git(['checkout', PR_HEAD_BRANCH], repoDir); + // git(['add', FINDINGS_PATH], repoDir); - const status = git(['status', '--porcelain'], repoDir); - if (!status) { - console.log(' findings.json 無變更,跳過 commit'); - return; - } + // const status = git(['status', '--porcelain'], repoDir); + // if (!status) { + // console.log(' findings.json 無變更,跳過 commit'); + // return; + // } - const out = git(['commit', '-m', 'chore: update ai-review findings [skip ci]'], repoDir); - const commitHash = out.match(/\[.+ ([a-f0-9]+)\]/)?.[1] || 'unknown'; - git(['push', remoteUrl, PR_HEAD_BRANCH], repoDir); - console.log(` ✅ persisted findings commit=${commitHash} push=${PR_HEAD_BRANCH}`); - } catch (e) { - console.log(` ⚠️ Runner failed: commit/push 失敗: ${e.message}`); + // const out = git(['commit', '-m', 'chore: update ai-review findings [skip ci]'], repoDir); + // const commitHash = out.match(/\[.+ ([a-f0-9]+)\]/)?.[1] || 'unknown'; + // git(['push', remoteUrl, PR_HEAD_BRANCH], repoDir); + // console.log(` ✅ persisted findings commit=${commitHash} push=${PR_HEAD_BRANCH}`); + // } catch (e) { + // console.log(` ⚠️ Runner failed: commit/push 失敗: ${e.message}`); + // } + + git(['config', 'user.email', 'ai-review[bot]@gitea'], repoDir); + git(['config', 'user.name', 'AI Review Bot'], repoDir); + git(['fetch', 'origin', PR_HEAD_BRANCH], repoDir); + git(['checkout', PR_HEAD_BRANCH], repoDir); + git(['add', FINDINGS_PATH], repoDir); + + const status = git(['status', '--porcelain'], repoDir); + if (!status) { + console.log(' findings.json 無變更,跳過 commit'); + return; } + + const out = git(['commit', '-m', 'chore: update ai-review findings [skip ci]'], repoDir); + const commitHash = out.match(/\[.+ ([a-f0-9]+)\]/)?.[1] || 'unknown'; + git(['push', remoteUrl, PR_HEAD_BRANCH], repoDir); + console.log(` ✅ persisted findings commit=${commitHash} push=${PR_HEAD_BRANCH}`); }