Compare commits
17 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 21fb9c1d94 | |||
| 607c9b82ea | |||
| 8acea007e7 | |||
| 953951145f | |||
| 1576e783fb | |||
| e017705c64 | |||
| 5f77b83a0f | |||
| da43cb02b0 | |||
| 577a930438 | |||
| 121f66b0b3 | |||
| faa808bb5f | |||
| 07df3ef4a5 | |||
| fc537958ca | |||
| 1c321b7ba2 | |||
| 710cd7308e | |||
| 59978c6fb5 | |||
| 519e04691d |
@@ -1,5 +1,6 @@
|
||||
FROM node:20-slim
|
||||
|
||||
# force rebuild to ensure git is installed
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||
git \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
+19
-27
@@ -1,42 +1,34 @@
|
||||
import { execSync } from 'child_process';
|
||||
import { spawnSync } from 'child_process';
|
||||
import path from 'path';
|
||||
import { GITEA_SERVER_URL, GITEA_REPOSITORY, GITEA_TOKEN, PR_HEAD_BRANCH, FINDINGS_PATH } from './config.js';
|
||||
|
||||
function exec(cmd, cwd) {
|
||||
return execSync(cmd, { cwd, stdio: 'pipe' }).toString().trim();
|
||||
function git(args, cwd) {
|
||||
const result = spawnSync('git', args, { cwd, encoding: 'utf8' });
|
||||
if (result.error) throw result.error;
|
||||
if (result.status !== 0) throw new Error((result.stderr || result.stdout || '').trim());
|
||||
return (result.stdout || '').trim();
|
||||
}
|
||||
|
||||
/**
|
||||
* Commit findings.json 並 push 到 PR 來源分支
|
||||
*/
|
||||
export function commitAndPush(workspace) {
|
||||
const repoDir = `${workspace}/${GITEA_REPOSITORY}`;
|
||||
const remoteUrl = `${GITEA_SERVER_URL.replace(/\/$/, '')}/${GITEA_REPOSITORY}.git`
|
||||
.replace('https://', `https://${GITEA_TOKEN}@`);
|
||||
export async function commitAndPush(workspace) {
|
||||
const repoDir = path.join(workspace, GITEA_REPOSITORY);
|
||||
const remoteUrl = GITEA_SERVER_URL.replace(/\/$/, '').replace('https://', `https://${GITEA_TOKEN}@`).replace('http://', `http://${GITEA_TOKEN}@`) + `/${GITEA_REPOSITORY}.git`;
|
||||
|
||||
try {
|
||||
// 設定 git 身份
|
||||
exec('git config user.email "ai-review[bot]@gitea"', repoDir);
|
||||
exec('git config user.name "AI Review Bot"', repoDir);
|
||||
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);
|
||||
|
||||
// 切換到來源分支
|
||||
exec(`git fetch origin ${PR_HEAD_BRANCH}`, repoDir);
|
||||
exec(`git checkout ${PR_HEAD_BRANCH}`, repoDir);
|
||||
|
||||
// 確認 findings.json 存在
|
||||
exec(`git add ${FINDINGS_PATH}`, repoDir);
|
||||
|
||||
// 檢查是否有變更
|
||||
const status = exec('git status --porcelain', repoDir);
|
||||
const status = git(['status', '--porcelain'], repoDir);
|
||||
if (!status) {
|
||||
console.log(' findings.json 無變更,跳過 commit');
|
||||
return;
|
||||
}
|
||||
|
||||
const commitMsg = 'chore: update ai-review findings [skip ci]';
|
||||
const commitHash = exec(`git commit -m "${commitMsg}"`, repoDir)
|
||||
.match(/\[.+ ([a-f0-9]+)\]/)?.[1] || 'unknown';
|
||||
|
||||
exec(`git push ${remoteUrl} ${PR_HEAD_BRANCH}`, repoDir);
|
||||
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}`);
|
||||
|
||||
+1
-1
@@ -91,7 +91,7 @@ async function main() {
|
||||
|
||||
// Step5: commit/push findings.json 到來源分支
|
||||
console.log('\n💾 Step5: 記憶區 Commit/Push');
|
||||
commitAndPush(WORKSPACE);
|
||||
await commitAndPush(WORKSPACE);
|
||||
|
||||
// Step6: 有 critical 問題則 exit 1
|
||||
console.log('\n🚦 Step6: 嚴重問題檢查');
|
||||
|
||||
Reference in New Issue
Block a user