From 20b0387b4d5c7abd61e36b35a6fb75982cfe3595 Mon Sep 17 00:00:00 2001 From: Jeffery Date: Fri, 26 Jun 2026 15:27:30 +0800 Subject: [PATCH] =?UTF-8?q?refactor(index):=20=E5=8C=AF=E5=87=BA=E7=B4=94?= =?UTF-8?q?=E5=87=BD=E5=BC=8F=E4=B8=A6=E5=83=85=E5=9C=A8=E7=9B=B4=E6=8E=A5?= =?UTF-8?q?=E5=9F=B7=E8=A1=8C=E6=99=82=E8=B7=91=E4=B8=BB=E6=B5=81=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/index.js | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/app/index.js b/app/index.js index 164709d..227b12f 100644 --- a/app/index.js +++ b/app/index.js @@ -1,3 +1,4 @@ +import { fileURLToPath } from 'node:url'; import { loadInputs, logInputs } from './lib/inputs.js'; import { Git } from './lib/git.js'; import { GiteaClient } from './lib/gitea.js'; @@ -191,9 +192,15 @@ function reportPull(pull, created) { } } -main().catch((err) => { - const detail = err?.stack || err?.message || String(err); - // 錯誤訊息/stack 可能夾帶 token,輸出到 CI 日誌前先遮蔽 - log.error(maskSecrets(detail, [process.env.GITEA_TOKEN])); - process.exit(1); -}); +// 純函式對外匯出,供測試使用(不觸發 main 流程) +export { truncateDiff, fallbackSummary, buildResolveBranchName, buildResolveBody }; + +// 僅在直接以 `node index.js` 執行時才跑主流程;被測試 import 時不執行 +if (process.argv[1] && fileURLToPath(import.meta.url) === process.argv[1]) { + main().catch((err) => { + const detail = err?.stack || err?.message || String(err); + // 錯誤訊息/stack 可能夾帶 token,輸出到 CI 日誌前先遮蔽 + log.error(maskSecrets(detail, [process.env.GITEA_TOKEN])); + process.exit(1); + }); +}