From c1f8aa3c72eb659763ab72d05aad6337b6aa0c3e Mon Sep 17 00:00:00 2001 From: Jeffery Date: Mon, 11 May 2026 13:54:44 +0000 Subject: [PATCH] =?UTF-8?q?feat:=20git=20=E6=93=8D=E4=BD=9C=20clone=20?= =?UTF-8?q?=E7=9A=84=20repo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/git.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/app/git.js b/app/git.js index 123178d..c9bc837 100644 --- a/app/git.js +++ b/app/git.js @@ -1,4 +1,6 @@ import { spawnSync } from 'child_process'; +import fs from 'fs'; +import path from 'path'; import { GITEA_SERVER_URL, GITEA_REPOSITORY, GITEA_TOKEN, PR_HEAD_BRANCH, FINDINGS_PATH } from './config.js'; function git(args, cwd) { @@ -9,16 +11,28 @@ function git(args, cwd) { } export async function commitAndPush(workspace) { - const repoDir = workspace; const remoteUrl = GITEA_SERVER_URL.replace(/\/$/, '') .replace('https://', `https://${GITEA_TOKEN}@`) .replace('http://', `http://${GITEA_TOKEN}@`) + `/${GITEA_REPOSITORY}.git`; + const repoDir = path.join(workspace, 'repo'); + try { + if (!fs.existsSync(repoDir)) { + git(['clone', '--depth=1', '--branch', PR_HEAD_BRANCH, remoteUrl, repoDir], workspace); + } + 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); + + // 將 findings.json 從 workspace 複製到 clone 的 repo + const srcFindings = path.join(workspace, FINDINGS_PATH); + const destFindings = path.join(repoDir, FINDINGS_PATH); + fs.mkdirSync(path.dirname(destFindings), { recursive: true }); + fs.copyFileSync(srcFindings, destFindings); + git(['add', FINDINGS_PATH], repoDir); const status = git(['status', '--porcelain'], repoDir);