From abac9a7596ec30487506eeb09099f615855f510f Mon Sep 17 00:00:00 2001 From: t8y2 <1156263951@qq.com> Date: Tue, 21 Jul 2026 17:52:02 +0800 Subject: [PATCH] fix(workflows): simplify similar issue comments --- .github/scripts/suggest-similar-issues.mjs | 16 ++-------------- .github/scripts/suggest-similar-issues.test.mjs | 7 +++---- 2 files changed, 5 insertions(+), 18 deletions(-) diff --git a/.github/scripts/suggest-similar-issues.mjs b/.github/scripts/suggest-similar-issues.mjs index 50b94f90af..8bd927fd58 100644 --- a/.github/scripts/suggest-similar-issues.mjs +++ b/.github/scripts/suggest-similar-issues.mjs @@ -446,22 +446,10 @@ function hasChinese(value) { return /\p{Script=Han}/u.test(String(value || "")); } -function safeTitle(value) { - return String(value || "") - .replace(/[\r\n]+/gu, " ") - .replace(/([\\`*_{}\[\]()<>#+.!|~-])/gu, "\\$1") - .trim(); -} - export function formatComment(issue, rankedCandidates) { const chinese = hasChinese(`${issue.title}\n${issue.body}`); - const lines = rankedCandidates.map(({ candidate }) => { - const state = String(candidate.state || "").toLowerCase() === "closed" - ? chinese ? "已关闭" : "Closed" - : chinese ? "进行中" : "Open"; - const stateSuffix = chinese ? `(${state})` : `(${state})`; - return `- #${candidate.number} — ${safeTitle(candidate.title)} ${stateSuffix}`; - }); + // GitHub expands issue references into links containing the title and number. + const lines = rankedCandidates.map(({ candidate }) => `- #${candidate.number}`); if (chinese) { return `${COMMENT_MARKER}\n以下 Issue 可能与当前问题相关:\n\n${lines.join("\n")}\n\n这些结果由机器人自动检索,尚未确认重复。如属于同一问题,建议在已有 Issue 中补充信息。`; diff --git a/.github/scripts/suggest-similar-issues.test.mjs b/.github/scripts/suggest-similar-issues.test.mjs index 961b81ef8f..cd12ab104a 100644 --- a/.github/scripts/suggest-similar-issues.test.mjs +++ b/.github/scripts/suggest-similar-issues.test.mjs @@ -212,16 +212,15 @@ test("ranks candidates, excludes the current issue and limits output", () => { assert.deepEqual(new Set(ranked.map(({ candidate }) => candidate.number)), new Set([82, 83])); }); -test("formats a cautious localized comment and escapes titles", () => { +test("formats a cautious localized comment with concise issue references", () => { const comment = formatComment(baseIssue, [ { candidate: { number: 82, title: "[Bug] [快捷键](https://example.com)", state: "closed" } }, ]); assert.match(comment, /^/u); - assert.match(comment, /#82/u); + assert.match(comment, /\n- #82\n/u); assert.match(comment, /尚未确认重复/u); - assert.match(comment, /已关闭/u); - assert.doesNotMatch(comment, /\]\(https:/u); + assert.doesNotMatch(comment, /快捷键|已关闭|https:/u); }); test("run searches and posts one idempotent comment", async (t) => {