refactor(index): 匯出純函式並僅在直接執行時跑主流程
This commit is contained in:
+13
-6
@@ -1,3 +1,4 @@
|
|||||||
|
import { fileURLToPath } from 'node:url';
|
||||||
import { loadInputs, logInputs } from './lib/inputs.js';
|
import { loadInputs, logInputs } from './lib/inputs.js';
|
||||||
import { Git } from './lib/git.js';
|
import { Git } from './lib/git.js';
|
||||||
import { GiteaClient } from './lib/gitea.js';
|
import { GiteaClient } from './lib/gitea.js';
|
||||||
@@ -191,9 +192,15 @@ function reportPull(pull, created) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
main().catch((err) => {
|
// 純函式對外匯出,供測試使用(不觸發 main 流程)
|
||||||
const detail = err?.stack || err?.message || String(err);
|
export { truncateDiff, fallbackSummary, buildResolveBranchName, buildResolveBody };
|
||||||
// 錯誤訊息/stack 可能夾帶 token,輸出到 CI 日誌前先遮蔽
|
|
||||||
log.error(maskSecrets(detail, [process.env.GITEA_TOKEN]));
|
// 僅在直接以 `node index.js` 執行時才跑主流程;被測試 import 時不執行
|
||||||
process.exit(1);
|
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);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user