refactor(pipeline 日誌): 步驟連號單一任務、輸入輸出與成敗訊息更明確、清除 bot-check 雜訊

This commit is contained in:
Jeffery
2026-06-23 15:15:24 +08:00
parent 0602f47100
commit 374bb4ec75
4 changed files with 89 additions and 121 deletions
+7 -28
View File
@@ -1,7 +1,7 @@
import axios from 'axios';
import https from 'https';
import { GITEA_TOKEN, GITEA_COMMENT_TOKEN, GITEA_SERVER_URL, GITEA_REPOSITORY, GITEA_SKIP_TLS_VERIFY, PR_NUMBER, PR_HEAD_SHA, PR_HEAD_BRANCH } from './config.js';
import { line, ok, warn } from './log.js';
import { line, warn } from './log.js';
const httpsAgent = GITEA_SKIP_TLS_VERIFY ? new https.Agent({ rejectUnauthorized: false }) : undefined;
const headers = (token = GITEA_TOKEN) => ({ Authorization: `token ${token}`, 'Content-Type': 'application/json' });
@@ -40,11 +40,9 @@ export async function getCommitMessageBySha(sha) {
timeout: 30000,
httpsAgent,
});
const message = extractCommitMessage(resp.data);
line(`bot-check commit api: sha=${sha} keys=${Object.keys(resp.data || {}).join(',') || 'empty'} message=${message ? 'found' : 'empty'}`);
return message;
return extractCommitMessage(resp.data);
} catch (e) {
warn(`bot-check commit api 失敗: sha=${sha} error=${e.message}`);
warn(`取得 commit 訊息失敗: sha=${sha} error=${e.message}`);
return '';
}
}
@@ -58,40 +56,21 @@ export async function getBranchHeadCommitMessage(branch = PR_HEAD_BRANCH) {
httpsAgent,
});
const sha = resp.data?.commit?.id || resp.data?.commit?.sha || '';
line(`bot-check branch api: branch=${branch} keys=${Object.keys(resp.data || {}).join(',') || 'empty'} sha=${sha || 'empty'} message=${extractCommitMessage(resp.data?.commit) ? 'found' : 'empty'}`);
return await getCommitMessageBySha(sha);
} catch (e) {
warn(`bot-check branch api 失敗: branch=${branch} error=${e.message}`);
warn(`取得分支 head 訊息失敗: branch=${branch} error=${e.message}`);
return '';
}
}
/** 檢查 PR headcommit sha 或分支 head)的訊息是否帶 [ai-review-bot] 標記,是則代表本次是自動提交、應跳過審查。 */
export async function shouldSkipBotCommit({ sha = PR_HEAD_SHA || process.env.GITHUB_SHA, branch = PR_HEAD_BRANCH } = {}) {
line(`bot-check start: PR_HEAD_SHA=${PR_HEAD_SHA || 'empty'} GITHUB_SHA=${process.env.GITHUB_SHA || 'empty'} sha=${sha || 'empty'} branch=${branch || 'empty'}`);
const shaMessage = await getCommitMessageBySha(sha);
if (sha) {
line(`bot-check sha: sha=${sha} message=${shaMessage ? 'found' : 'empty'} outcome=${getBotReviewOutcome(shaMessage)}`);
if (shaMessage.includes('[ai-review-bot]')) {
ok('bot-check matched commit sha marker');
return true;
}
} else {
line('bot-check skip sha lookup because sha is empty');
}
if (sha && shaMessage.includes('[ai-review-bot]')) return true;
const branchMessage = await getBranchHeadCommitMessage(branch);
if (branch) {
line(`bot-check branch: branch=${branch} head_message=${branchMessage ? 'found' : 'empty'} outcome=${getBotReviewOutcome(branchMessage)}`);
if (branchMessage.includes('[ai-review-bot]')) {
ok('bot-check matched branch head marker');
return true;
}
} else {
line('bot-check skip branch lookup because branch is empty');
}
if (branch && branchMessage.includes('[ai-review-bot]')) return true;
line('bot-check no [ai-review-bot] marker found');
return false;
}