feat: encode ai review outcome in commit marker

This commit is contained in:
2026-05-15 14:47:02 +00:00
parent bfa01721e4
commit 066b21aa5c
6 changed files with 35 additions and 72 deletions
+7 -20
View File
@@ -13,6 +13,11 @@ function extractCommitMessage(payload) {
|| '';
}
export function getBotReviewOutcome(message) {
const match = String(message || '').match(/\[ai-review-bot\](?:\[(success|failure)\])?/i);
return match?.[1]?.toLowerCase() || 'unknown';
}
/**
* 取得 PR 的 Git Diff 內容,已自動排除 .gitea/ 資料夾。
*/
@@ -71,7 +76,7 @@ export async function shouldSkipBotCommit({ sha = PR_HEAD_SHA || process.env.GIT
const shaMessage = await getCommitMessageBySha(sha);
if (sha) {
console.log(` 🔎 bot-check: sha=${sha} message=${shaMessage ? 'found' : 'empty'}`);
console.log(` 🔎 bot-check: sha=${sha} message=${shaMessage ? 'found' : 'empty'} outcome=${getBotReviewOutcome(shaMessage)}`);
if (shaMessage.includes('[ai-review-bot]')) {
console.log(' ✅ bot-check: matched commit sha marker');
return true;
@@ -82,7 +87,7 @@ export async function shouldSkipBotCommit({ sha = PR_HEAD_SHA || process.env.GIT
const branchMessage = await getBranchHeadCommitMessage(branch);
if (branch) {
console.log(` 🔎 bot-check: branch=${branch} head_message=${branchMessage ? 'found' : 'empty'}`);
console.log(` 🔎 bot-check: branch=${branch} head_message=${branchMessage ? 'found' : 'empty'} outcome=${getBotReviewOutcome(branchMessage)}`);
if (branchMessage.includes('[ai-review-bot]')) {
console.log(' ✅ bot-check: matched branch head marker');
return true;
@@ -95,24 +100,6 @@ export async function shouldSkipBotCommit({ sha = PR_HEAD_SHA || process.env.GIT
return false;
}
export async function setCommitStatus(sha, state, description, context = 'ai-review/critical', targetUrl = '') {
if (!sha) throw new Error('commit sha is required for status update');
const payload = {
state,
context,
description,
};
if (targetUrl) payload.target_url = targetUrl;
const resp = await axios.post(api(`/repos/${GITEA_REPOSITORY}/statuses/${encodeURIComponent(sha)}`), payload, {
headers: headers(),
timeout: 30000,
httpsAgent,
});
console.log(` ✅ status: sha=${sha} state=${state} context=${context} description=${description}`);
return resp.data;
}
/**
* 過濾 diff 內容,移除路徑符合 excludePrefixes 的區塊。
* 每個區塊以 "diff --git a/<prefix>" 開頭判斷,使用 startsWith 精確比對前綴。