Compare commits

...

8 Commits

3 changed files with 43 additions and 23 deletions
+5 -5
View File
@@ -1,9 +1,9 @@
FROM node:20-slim FROM alpine
# force rebuild to ensure git is installed RUN apk add --no-cache bash nodejs npm git \
RUN apt-get update && apt-get install -y --no-install-recommends \ && node --version \
git \ && npm --version \
&& rm -rf /var/lib/apt/lists/* && git --version
WORKDIR /action WORKDIR /action
+1
View File
@@ -27,6 +27,7 @@
--- ---
每個階段都會加上明確的 log,並確保即使部分功能未完成也能降級執行、不會中斷 pipeline。 每個階段都會加上明確的 log,並確保即使部分功能未完成也能降級執行、不會中斷 pipeline。
每次執行後請貼 log,我會協助 debug。 每次執行後請貼 log,我會協助 debug。
+37 -18
View File
@@ -11,26 +11,45 @@ function git(args, cwd) {
export async function commitAndPush(workspace) { export async function commitAndPush(workspace) {
const repoDir = path.join(workspace, GITEA_REPOSITORY); 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`; const remoteUrl = GITEA_SERVER_URL.replace(/\/$/, '')
.replace('https://', `https://${GITEA_TOKEN}@`)
.replace('http://', `http://${GITEA_TOKEN}@`) + `/${GITEA_REPOSITORY}.git`;
try { // try {
git(['config', 'user.email', 'ai-review[bot]@gitea'], repoDir); // git(['config', 'user.email', 'ai-review[bot]@gitea'], repoDir);
git(['config', 'user.name', 'AI Review Bot'], repoDir); // git(['config', 'user.name', 'AI Review Bot'], repoDir);
git(['fetch', 'origin', PR_HEAD_BRANCH], repoDir); // git(['fetch', 'origin', PR_HEAD_BRANCH], repoDir);
git(['checkout', PR_HEAD_BRANCH], repoDir); // git(['checkout', PR_HEAD_BRANCH], repoDir);
git(['add', FINDINGS_PATH], repoDir); // git(['add', FINDINGS_PATH], repoDir);
const status = git(['status', '--porcelain'], repoDir); // const status = git(['status', '--porcelain'], repoDir);
if (!status) { // if (!status) {
console.log(' findings.json 無變更,跳過 commit'); // console.log(' findings.json 無變更,跳過 commit');
return; // return;
} // }
const out = git(['commit', '-m', 'chore: update ai-review findings [skip ci]'], repoDir); // const out = git(['commit', '-m', 'chore: update ai-review findings [skip ci]'], repoDir);
const commitHash = out.match(/\[.+ ([a-f0-9]+)\]/)?.[1] || 'unknown'; // const commitHash = out.match(/\[.+ ([a-f0-9]+)\]/)?.[1] || 'unknown';
git(['push', remoteUrl, PR_HEAD_BRANCH], repoDir); // git(['push', remoteUrl, PR_HEAD_BRANCH], repoDir);
console.log(` ✅ persisted findings commit=${commitHash} push=${PR_HEAD_BRANCH}`); // console.log(` ✅ persisted findings commit=${commitHash} push=${PR_HEAD_BRANCH}`);
} catch (e) { // } catch (e) {
console.log(` ⚠️ Runner failed: commit/push 失敗: ${e.message}`); // 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}`);
} }