From ce53c67cac04b13a1d9048b4f08287d757f7f8ec Mon Sep 17 00:00:00 2001 From: Jeffery Date: Fri, 15 May 2026 15:05:52 +0000 Subject: [PATCH] fix: fail workflow on bot failure marker --- app/main.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/app/main.js b/app/main.js index 99a9b90..ea84459 100644 --- a/app/main.js +++ b/app/main.js @@ -1,7 +1,7 @@ import path from 'path'; 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, shouldSkipBotCommit } from './gitea.js'; +import { getPRDiff, postComment, getCommitMessageBySha, getBotReviewOutcome, shouldSkipBotCommit } from './gitea.js'; import { analyzeWithRole, loadOldFindings, mergeFindings, sortByLevel, deduplicateWithAI, loadExclusions, applyExclusions, filterFalsePositivesWithAI } from './findings.js'; import { saveFindings, postOldFindingsComment, postNewNonCriticalComment, postNewCriticalComments } from './comments.js'; import { cloneRepo, commitAndPush, getRepoState } from './git.js'; @@ -15,6 +15,16 @@ async function main() { console.log(` repo=${GITEA_REPOSITORY} PR=#${PR_NUMBER}`); console.log(` ${PR_HEAD_BRANCH} -> ${PR_BASE_BRANCH}`); + const headSha = process.env.PR_HEAD_SHA || process.env.GITHUB_SHA || ''; + const headMessage = await getCommitMessageBySha(headSha); + const headOutcome = getBotReviewOutcome(headMessage); + console.log(` 🔎 head check: sha=${headSha || 'empty'} outcome=${headOutcome}`); + if (headMessage.includes('[ai-review-bot]') && headOutcome === 'failure') { + console.log(' ❌ 偵測到 [ai-review-bot][failure],直接讓 workflow 失敗'); + console.log('='.repeat(60)); + process.exit(1); + } + if (await shouldSkipBotCommit()) { console.log(' 🤖 偵測到 [ai-review-bot] 自動提交,直接完成 action'); console.log('='.repeat(60));