From a7824cff29ff96805708b410a88159a3abb0483a Mon Sep 17 00:00:00 2001 From: Jeffery Date: Fri, 3 Jul 2026 17:47:48 +0800 Subject: [PATCH] =?UTF-8?q?refactor(main):=20=E5=8C=AF=E5=87=BA=20main=20?= =?UTF-8?q?=E4=B8=A6=E5=AE=88=E8=A1=9B=20auto-run=20=E4=BB=A5=E5=88=A9?= =?UTF-8?q?=E6=B8=AC=E8=A9=A6=E8=BC=89=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/main.js b/src/main.js index fdc9bfd..2c1ffee 100644 --- a/src/main.js +++ b/src/main.js @@ -1,4 +1,5 @@ import path from 'path'; +import { pathToFileURL } from 'url'; import { GITEA_REPOSITORY, PR_NUMBER, PR_HEAD_BRANCH, PR_BASE_BRANCH, getLLMConfig, FINDINGS_PATH, EXCLUSIONS_PATH } from './config.js'; import { loadRoles, getRoleIntro } from './roles.js'; import { getPRDiff, postComment, getCommitMessageBySha, getBotReviewOutcome, shouldSkipBotCommit } from './gitea.js'; @@ -52,7 +53,7 @@ const WORKSPACE = process.env.GITHUB_WORKSPACE || '/workspace'; * 降級處理:Step4 對話收斂、Step5 角色介紹 comment 與個別角色分析、Step6 clone repo、 * Step8 Review 發布等非致命步驟失敗時,僅 `warn` 後繼續執行。 */ -async function main() { +export async function main() { section('AI Code Review Pipeline'); // Step1 啟動 @@ -236,7 +237,11 @@ async function main() { section('Pipeline 結束'); } -main().catch(e => { - error(`Runner failed: ${e.message}`); - process.exit(1); -}); +// 僅在作為 CLI 進入點(node src/main.js)執行時自動啟動 pipeline; +// 被 import(例如單元測試)時不自動執行,方便注入 mock 測試各分支。 +if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) { + main().catch(e => { + error(`Runner failed: ${e.message}`); + process.exit(1); + }); +}