Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c1f8aa3c72 | |||
| 8a28d1f1ef | |||
| d04f4dd2bb | |||
| f5cf5950bd | |||
| eae73092ad | |||
| 69624a542e | |||
| 8aa273b8bd |
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
FROM alpine
|
FROM alpine
|
||||||
|
|
||||||
RUN apk add --no-cache nodejs npm git \
|
RUN apk add --no-cache bash nodejs npm git \
|
||||||
&& node --version \
|
&& node --version \
|
||||||
&& npm --version \
|
&& npm --version \
|
||||||
&& git --version
|
&& git --version
|
||||||
|
|||||||
+14
-1
@@ -1,4 +1,5 @@
|
|||||||
import { spawnSync } from 'child_process';
|
import { spawnSync } from 'child_process';
|
||||||
|
import fs from 'fs';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import { GITEA_SERVER_URL, GITEA_REPOSITORY, GITEA_TOKEN, PR_HEAD_BRANCH, FINDINGS_PATH } from './config.js';
|
import { GITEA_SERVER_URL, GITEA_REPOSITORY, GITEA_TOKEN, PR_HEAD_BRANCH, FINDINGS_PATH } from './config.js';
|
||||||
|
|
||||||
@@ -10,16 +11,28 @@ function git(args, cwd) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function commitAndPush(workspace) {
|
export async function commitAndPush(workspace) {
|
||||||
const repoDir = path.join(workspace, GITEA_REPOSITORY);
|
|
||||||
const remoteUrl = GITEA_SERVER_URL.replace(/\/$/, '')
|
const remoteUrl = GITEA_SERVER_URL.replace(/\/$/, '')
|
||||||
.replace('https://', `https://${GITEA_TOKEN}@`)
|
.replace('https://', `https://${GITEA_TOKEN}@`)
|
||||||
.replace('http://', `http://${GITEA_TOKEN}@`) + `/${GITEA_REPOSITORY}.git`;
|
.replace('http://', `http://${GITEA_TOKEN}@`) + `/${GITEA_REPOSITORY}.git`;
|
||||||
|
|
||||||
|
const repoDir = path.join(workspace, 'repo');
|
||||||
|
|
||||||
try {
|
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.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);
|
||||||
|
|
||||||
|
// 將 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);
|
git(['add', FINDINGS_PATH], repoDir);
|
||||||
|
|
||||||
const status = git(['status', '--porcelain'], repoDir);
|
const status = git(['status', '--porcelain'], repoDir);
|
||||||
|
|||||||
Reference in New Issue
Block a user