fix(ai-review): 避免建問題模式阻擋失效與連結累積
This commit is contained in:
@@ -832,6 +832,40 @@ async function resolveOldComments({ ctx, gitea, currentRunCommentIds }) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 建問題模式:只將 PR 上舊的「追蹤問題連結」留言標註為過時,不觸碰 issue 內審查內容。
|
||||
*
|
||||
* @param {Object} params - 解構參數。
|
||||
* @param {Object} params.ctx - 執行環境 context(`loadContext()` 產出)。
|
||||
* @param {Object} params.gitea - Gitea API 模組,需提供 `whoAmI`、`listIssueComments`、`editIssueComment`。
|
||||
* @returns {Promise<void>} 無回傳值;失敗時只記 WRN,不阻斷主流程。
|
||||
*/
|
||||
async function resolveOldIssueLinkComments({ ctx, gitea }) {
|
||||
let botLogin = '';
|
||||
try {
|
||||
botLogin = (await gitea.whoAmI(ctx)).login || '';
|
||||
} catch (err) {
|
||||
log('建問題', 'WRN', `無法取得 bot 身分(${err.message}),略過舊追蹤連結標註。`);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const comments = await gitea.listIssueComments(ctx);
|
||||
let outdatedCount = 0;
|
||||
for (const comment of comments) {
|
||||
const isBot = comment.user && comment.user.login === botLogin;
|
||||
const body = typeof comment.body === 'string' ? comment.body : '';
|
||||
const isIssueLink = body.includes(templates.MARK) && body.includes('## 🔍 AI Code Review|已建立追蹤問題');
|
||||
if (!isBot || !isIssueLink || body.startsWith(templates.OUTDATED_PREFIX)) continue;
|
||||
await gitea.editIssueComment(ctx, comment.id, `${templates.OUTDATED_PREFIX}${body}`);
|
||||
outdatedCount += 1;
|
||||
}
|
||||
log('建問題', 'INF', `舊追蹤 issue 連結已標註〔已過時〕:${outdatedCount} 則。`);
|
||||
} catch (err) {
|
||||
log('建問題', 'WRN', `標註舊追蹤 issue 連結失敗:${err.message}。`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 步驟 9:嚴重問題逐條掛在 PR 程式碼行上留言(建立 code review);
|
||||
* 建立 review 失敗時降級為一般留言逐條發布(留言內補上檔案與行號位置)。
|
||||
@@ -884,5 +918,6 @@ module.exports = {
|
||||
postSevereToIssue,
|
||||
postOthersToIssue,
|
||||
resolveOldComments,
|
||||
resolveOldIssueLinkComments,
|
||||
postSevereComments,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user