fix(github): parse bot database metadata

This commit is contained in:
t8y2
2026-07-21 21:30:02 +08:00
parent 754c8b4a53
commit b54110036b
3 changed files with 34 additions and 3 deletions
+12 -2
View File
@@ -142,12 +142,22 @@ function extractIssueFormSection(body, predicate) {
return "";
}
function extractInlineField(body, predicate) {
const matches = String(body || "").matchAll(/^\s*\*\*(.+?)\*\*\s*[::]\s*(.+?)\s*$/gm);
for (const match of matches) {
if (predicate(match[1].trim())) return match[2].trim();
}
return "";
}
function extractDatabaseField(body) {
return extractIssueFormSection(body, (heading) => (
const matchesDatabaseHeading = (heading) => (
heading.includes("数据库类型") ||
heading.toLowerCase().includes("database type") ||
/^database$/i.test(heading)
));
);
return extractIssueFormSection(body, matchesDatabaseHeading)
|| extractInlineField(body, matchesDatabaseHeading);
}
function extractPriorityField(body) {
+6 -1
View File
@@ -149,7 +149,12 @@ function parseIssueSections(body) {
}
function databaseField(body) {
return parseIssueSections(body).find(({ heading }) => /数据库类型|database type/iu.test(heading))?.content || "";
const section = parseIssueSections(body).find(({ heading }) => /数据库类型|database type/iu.test(heading))?.content;
if (section) return section;
// Bot-created issues historically used a bold inline metadata field instead of an issue-form heading.
const inline = String(body || "").match(/^\s*\*\*(?:数据库类型(?:和版本)?|database type)\*\*\s*[::]\s*(.+?)\s*$/imu);
return inline?.[1]?.trim() || "";
}
function relevantBody(body) {
@@ -98,6 +98,22 @@ test("detects database conflicts from issue forms before labels are added", () =
assert.equal(scoreCandidate(issue, postgresCandidate).accepted, true);
});
test("detects database conflicts from legacy bot metadata", () => {
const issue = {
...baseIssue,
body: "**来源**: QQ 群反馈\n**数据库类型和版本**: PostgreSQL 16\n\n## 原始描述\n修改后保存失败。",
labels: [{ name: "bug" }],
};
const candidate = {
number: 102,
title: "MySQL 查询结果修改后保存失败",
body: "### 数据库类型和版本\n\nMySQL 8.0\n\n### 问题描述\n\n修改后保存失败。",
labels: [{ name: "bug" }],
};
assert.equal(scoreCandidate(issue, candidate).reason, "database-mismatch");
});
test("does not treat a shared database product as issue similarity", () => {
const issue = {
number: 4048,