fix(triage): parse level-2 issue headings (ISSUE-179)

Signed-off-by: dongmucat <1127093059@qq.com>
This commit is contained in:
dongmucat 2026-10-02 02:20:20 +08:00
parent 735259728f
commit 906a5e6c19
2 changed files with 68 additions and 1 deletions

View file

@ -27,7 +27,7 @@ import { buildMaintainerHandoffBrief } from "./issue-handoff-brief.ts";
export function parseIssueBody(body: string | null): ParsedIssueBody {
const sections: Record<string, string> = {};
const rawBody = body ?? "";
const headingMatches = [...rawBody.matchAll(/^###\s+(.+)$/gm)];
const headingMatches = [...rawBody.matchAll(/^#{2,3}\s+(.+)$/gm)];
for (let index = 0; index < headingMatches.length; index += 1) {
const current = headingMatches[index];

View file

@ -0,0 +1,67 @@
import type { GitHubIssue } from "./github.ts";
import { analyzeIssue, parseIssueBody } from "./issue-triage-lib.ts";
function assertEquals(actual: unknown, expected: unknown) {
const actualJson = JSON.stringify(actual);
const expectedJson = JSON.stringify(expected);
if (actualJson !== expectedJson) {
throw new Error(`Expected ${expectedJson}, received ${actualJson}`);
}
}
function featureIssue(body: string): GitHubIssue {
return {
number: 1,
title: "[Feature] Improve issue triage",
body,
state: "open",
labels: [{ name: "enhancement" }],
comments: 0,
created_at: "2026-10-01T00:00:00Z",
updated_at: "2026-10-01T00:00:00Z",
user: { login: "contributor" },
html_url: "https://github.com/iflytek/skillhub/issues/1",
};
}
Deno.test("level-2 headings satisfy required feature sections", () => {
const result = analyzeIssue(
featureIssue(`## Problem
Filled issues are marked as incomplete.
## Proposed solution
Recognize level-2 headings during triage.`),
[],
new Date("2026-10-01T00:00:00Z"),
);
assertEquals(result.missingFields, []);
assertEquals(result.route === "needs-info", false);
});
Deno.test("level-3 Issue Form headings keep their existing behavior", () => {
const parsed = parseIssueBody(`### Problem
Filled issues are marked as incomplete.
### Proposed Solution
Recognize headings generated by Issue Forms.`);
assertEquals(parsed.sections, {
problem: "Filled issues are marked as incomplete.",
"proposed solution": "Recognize headings generated by Issue Forms.",
});
});
Deno.test("mixed level-2 and level-3 headings are parsed together", () => {
const parsed = parseIssueBody(`## Problem
Filled issues are marked as incomplete.
### Proposed Solution
Recognize both supported heading levels.`);
assertEquals(parsed.sections, {
problem: "Filled issues are marked as incomplete.",
"proposed solution": "Recognize both supported heading levels.",
});
});