Compare commits
20 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| af51ffacee | |||
| d9c55ca347 | |||
| 21fb9c1d94 | |||
| 607c9b82ea | |||
| 8acea007e7 | |||
| 953951145f | |||
| 1576e783fb | |||
| e017705c64 | |||
| 5f77b83a0f | |||
| da43cb02b0 | |||
| 577a930438 | |||
| 121f66b0b3 | |||
| faa808bb5f | |||
| 07df3ef4a5 | |||
| fc537958ca | |||
| 1c321b7ba2 | |||
| 710cd7308e | |||
| 59978c6fb5 | |||
| 519e04691d | |||
| 5ae0549453 |
+1
-5
@@ -1,8 +1,4 @@
|
||||
FROM node:20-slim
|
||||
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||
git \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
FROM node:20
|
||||
|
||||
WORKDIR /action
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
|
||||
---
|
||||
|
||||
|
||||
每個階段都會加上明確的 log,並確保即使部分功能未完成也能降級執行、不會中斷 pipeline。
|
||||
|
||||
每次執行後請貼 log,我會協助 debug。
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
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 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();
|
||||
}
|
||||
|
||||
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(['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}`);
|
||||
} catch (e) {
|
||||
console.log(` ⚠️ Runner failed: commit/push 失敗: ${e.message}`);
|
||||
}
|
||||
}
|
||||
+13
-4
@@ -3,6 +3,7 @@ import { loadRoles, getRoleIntro } from './roles.js';
|
||||
import { getPRDiff, postComment } from './gitea.js';
|
||||
import { analyzeWithRole, loadOldFindings, mergeFindings, sortByLevel, deduplicateWithAI } from './findings.js';
|
||||
import { saveFindings, postOldFindingsComment, postNewNonCriticalComment, postNewCriticalComments } from './comments.js';
|
||||
import { commitAndPush } from './git.js';
|
||||
|
||||
const WORKSPACE = process.env.GITHUB_WORKSPACE || '/workspace';
|
||||
|
||||
@@ -88,11 +89,19 @@ async function main() {
|
||||
console.log(` ⚠️ comment 發布失敗(繼續執行): ${e.message}`);
|
||||
}
|
||||
|
||||
console.log('\n💾 Step5: 記憶區 Commit/Push(待實作)');
|
||||
console.log(' [stub] commit & push findings.json...');
|
||||
// Step5: commit/push findings.json 到來源分支
|
||||
console.log('\n💾 Step5: 記憶區 Commit/Push');
|
||||
await commitAndPush(WORKSPACE);
|
||||
|
||||
console.log('\n🚦 Step6: 嚴重問題檢查(待實作)');
|
||||
console.log(' [stub] 檢查 critical findings...');
|
||||
// Step6: 有 critical 問題則 exit 1
|
||||
console.log('\n🚦 Step6: 嚴重問題檢查');
|
||||
const criticalCount = sorted.filter(f => f.level === 'critical').length;
|
||||
if (criticalCount > 0) {
|
||||
console.log(` ❌ 發現 ${criticalCount} 個嚴重問題,workflow 結束(exit 1)`);
|
||||
console.log('='.repeat(60));
|
||||
process.exit(1);
|
||||
}
|
||||
console.log(' ✅ 無嚴重問題');
|
||||
|
||||
console.log('\n✅ Pipeline 完成');
|
||||
console.log('='.repeat(60));
|
||||
|
||||
Reference in New Issue
Block a user