feat: add issue board audit cli
This commit is contained in:
+482
-2
@@ -13,6 +13,8 @@ const DEFAULT_COMMANDER_BRIEF_CLAUDEQQ_BASE_URL = "http://backend-core:8080/api/
|
||||
const DEFAULT_COMMANDER_BRIEF_CLAUDEQQ_USER_ID = "645275593";
|
||||
const CODE_QUEUE_BOARD_TARGET_ISSUE = 20;
|
||||
const COMMANDER_BRIEF_TARGET_ISSUE = 24;
|
||||
const DEFAULT_BOARD_KNOWN_META_ISSUES = [CODE_QUEUE_BOARD_TARGET_ISSUE, COMMANDER_BRIEF_TARGET_ISSUE] as const;
|
||||
const BOARD_AUDIT_REQUIRED_COLUMNS = ["branch", "acceptance", "relatedTask", "progress"] as const;
|
||||
const ISSUE_VIEW_JSON_FIELDS = ["body", "title", "state", "comments", "number", "url", "author", "createdAt", "updatedAt"] as const;
|
||||
const ISSUE_LIST_JSON_FIELDS = ["number", "title", "state", "url", "updatedAt", "createdAt", "author", "labels"] as const;
|
||||
const PR_JSON_FIELDS = ["body", "title", "state", "number", "url", "author", "head", "base", "draft", "createdAt", "updatedAt"] as const;
|
||||
@@ -44,6 +46,8 @@ type EscapeFindingClassification = "suspected-pollution" | "explanatory-mention"
|
||||
type EscapeFindingSeverity = "low" | "medium" | "high";
|
||||
type EscapeBodyKind = "issue-body" | "comment-body";
|
||||
type CleanupSuggestionAction = "rewrite-issue-body-with-body-file" | "review-comment-manually" | "review-body-length" | "no-cleanup-needed";
|
||||
type BoardSectionKind = "open" | "closed";
|
||||
type BoardRequiredColumn = typeof BOARD_AUDIT_REQUIRED_COLUMNS[number];
|
||||
|
||||
type GitHubDegradedReason =
|
||||
| "missing-binary"
|
||||
@@ -175,6 +179,52 @@ interface EscapeScanErrorFinding {
|
||||
|
||||
type EscapeScanEntry = EscapeMatchFinding | EscapeScanErrorFinding;
|
||||
|
||||
interface BoardTableRow {
|
||||
section: BoardSectionKind;
|
||||
lineNumber: number;
|
||||
raw: string;
|
||||
cells: string[];
|
||||
issueNumbers: number[];
|
||||
issueNumber: number | null;
|
||||
title: string | null;
|
||||
columns: Partial<Record<BoardRequiredColumn, string>>;
|
||||
}
|
||||
|
||||
interface BoardTableSection {
|
||||
kind: BoardSectionKind;
|
||||
heading: string;
|
||||
headingLine: number;
|
||||
headerLine: number;
|
||||
headers: string[];
|
||||
rows: BoardTableRow[];
|
||||
}
|
||||
|
||||
interface BoardIssueEntry {
|
||||
number: number;
|
||||
title: string;
|
||||
state: string;
|
||||
url: string;
|
||||
}
|
||||
|
||||
interface BoardIgnoredIssue {
|
||||
number: number;
|
||||
reason: "known-meta" | "ignored";
|
||||
title?: string;
|
||||
state?: string;
|
||||
url?: string;
|
||||
}
|
||||
|
||||
interface BoardRowValidationWarning {
|
||||
issueNumber: number | null;
|
||||
section: BoardSectionKind;
|
||||
lineNumber: number;
|
||||
kind: string;
|
||||
message: string;
|
||||
missingColumns?: BoardRequiredColumn[];
|
||||
columns?: Partial<Record<BoardRequiredColumn, string>>;
|
||||
rowPreview: string;
|
||||
}
|
||||
|
||||
interface GitHubCommandResult {
|
||||
ok: boolean;
|
||||
repo: string;
|
||||
@@ -197,6 +247,9 @@ interface GitHubOptions {
|
||||
repo: string;
|
||||
dryRun: boolean;
|
||||
limit: number;
|
||||
boardIssue: number;
|
||||
knownMetaIssues: number[];
|
||||
ignoredIssues: number[];
|
||||
draft: boolean;
|
||||
notifyClaudeQqBriefDiff: boolean;
|
||||
allowShortBody: boolean;
|
||||
@@ -347,6 +400,31 @@ function labelsOption(args: string[]): string[] {
|
||||
return labels;
|
||||
}
|
||||
|
||||
function positiveIntegerValuesOption(args: string[], name: string): number[] {
|
||||
const values: number[] = [];
|
||||
const seen = new Set<number>();
|
||||
for (const raw of optionValues(args, name)) {
|
||||
const parts = raw.split(",").map((value) => value.trim()).filter((value) => value.length > 0);
|
||||
if (parts.length === 0) throw new Error(`${name} requires at least one positive integer`);
|
||||
for (const part of parts) {
|
||||
const value = Number(part.replace(/^#/u, ""));
|
||||
if (!Number.isInteger(value) || value <= 0) throw new Error(`${name} values must be positive issue numbers`);
|
||||
if (seen.has(value)) continue;
|
||||
values.push(value);
|
||||
seen.add(value);
|
||||
}
|
||||
}
|
||||
return values;
|
||||
}
|
||||
|
||||
function positiveIntegerSingleOption(args: string[], name: string, defaultValue: number): number {
|
||||
const raw = optionValue(args, name);
|
||||
if (raw === undefined) return defaultValue;
|
||||
const value = Number(raw.replace(/^#/u, ""));
|
||||
if (!Number.isInteger(value) || value <= 0) throw new Error(`${name} must be a positive issue number`);
|
||||
return value;
|
||||
}
|
||||
|
||||
function positiveIntegerOption(args: string[], name: string, defaultValue: number, maxValue: number): number {
|
||||
const raw = optionValue(args, name);
|
||||
if (raw === undefined) return defaultValue;
|
||||
@@ -396,7 +474,7 @@ function parseIssueBodyProfile(args: string[]): IssueBodyProfileOption {
|
||||
}
|
||||
|
||||
function validateKnownOptions(args: string[]): void {
|
||||
const valueOptions = new Set(["--repo", "--limit", "--title", "--body-file", "--body", "--base", "--head", "--json", "--state", "--mode", "--expect-updated-at", "--expect-body-sha", "--body-profile", "--label"]);
|
||||
const valueOptions = new Set(["--repo", "--limit", "--board-issue", "--known-meta-issue", "--ignore-issue", "--title", "--body-file", "--body", "--base", "--head", "--json", "--state", "--mode", "--expect-updated-at", "--expect-body-sha", "--body-profile", "--label"]);
|
||||
const flagOptions = new Set(["--dry-run", "--draft", "--notify-claudeqq-brief-diff", "--allow-short-body"]);
|
||||
for (let index = 0; index < args.length; index += 1) {
|
||||
const arg = args[index];
|
||||
@@ -417,7 +495,10 @@ function parseOptions(args: string[]): GitHubOptions {
|
||||
return {
|
||||
repo: optionValue(args, "--repo") ?? DEFAULT_REPO,
|
||||
dryRun: hasFlag(args, "--dry-run"),
|
||||
limit: positiveIntegerOption(args, "--limit", 30, 100),
|
||||
limit: positiveIntegerOption(args, "--limit", top === "issue" && sub === "board-audit" ? 100 : 30, 100),
|
||||
boardIssue: positiveIntegerSingleOption(args, "--board-issue", CODE_QUEUE_BOARD_TARGET_ISSUE),
|
||||
knownMetaIssues: positiveIntegerValuesOption(args, "--known-meta-issue"),
|
||||
ignoredIssues: positiveIntegerValuesOption(args, "--ignore-issue"),
|
||||
draft: hasFlag(args, "--draft"),
|
||||
notifyClaudeQqBriefDiff: hasFlag(args, "--notify-claudeqq-brief-diff"),
|
||||
allowShortBody: hasFlag(args, "--allow-short-body"),
|
||||
@@ -1100,6 +1181,227 @@ function issueListSummary(issue: GitHubIssue, fields: IssueListJsonField[]): Rec
|
||||
return selected;
|
||||
}
|
||||
|
||||
function boardIssueEntry(issue: GitHubIssue): BoardIssueEntry {
|
||||
return {
|
||||
number: issue.number,
|
||||
title: issue.title,
|
||||
state: issue.state,
|
||||
url: issue.html_url,
|
||||
};
|
||||
}
|
||||
|
||||
function sortedIssueEntries(issues: BoardIssueEntry[]): BoardIssueEntry[] {
|
||||
return issues.slice().sort((a, b) => a.number - b.number);
|
||||
}
|
||||
|
||||
function mergedKnownMetaIssues(options: GitHubOptions): number[] {
|
||||
const seen = new Set<number>();
|
||||
const values: number[] = [];
|
||||
for (const issueNumber of [...DEFAULT_BOARD_KNOWN_META_ISSUES, ...options.knownMetaIssues]) {
|
||||
if (seen.has(issueNumber)) continue;
|
||||
seen.add(issueNumber);
|
||||
values.push(issueNumber);
|
||||
}
|
||||
return values;
|
||||
}
|
||||
|
||||
function boardIgnoreMap(options: GitHubOptions): Map<number, "known-meta" | "ignored"> {
|
||||
const ignored = new Map<number, "known-meta" | "ignored">();
|
||||
for (const issueNumber of mergedKnownMetaIssues(options)) ignored.set(issueNumber, "known-meta");
|
||||
for (const issueNumber of options.ignoredIssues) ignored.set(issueNumber, "ignored");
|
||||
return ignored;
|
||||
}
|
||||
|
||||
function stripMarkdownInline(text: string): string {
|
||||
return text
|
||||
.replace(/\[[^\]]*]\(([^)]*)\)/g, "$1")
|
||||
.replace(/<[^>]+>/g, "")
|
||||
.replace(/[*_`~]/g, "")
|
||||
.trim();
|
||||
}
|
||||
|
||||
function normalizeBoardHeader(header: string): string {
|
||||
return stripMarkdownInline(header).toLowerCase().replace(/\s+/g, "");
|
||||
}
|
||||
|
||||
function boardHeaderColumnKind(header: string): BoardRequiredColumn | null {
|
||||
const normalized = normalizeBoardHeader(header);
|
||||
if (["branch", "分支", "目标分支", "工作分支"].includes(normalized)) return "branch";
|
||||
if (["acceptance", "验收", "验收状态", "验收结果", "验收标准"].includes(normalized)) return "acceptance";
|
||||
if (["relatedtask", "task", "codequeue", "codequeuetask", "相关任务", "任务", "codequeue任务", "cq任务"].includes(normalized)) return "relatedTask";
|
||||
if (["progress", "进度", "状态", "当前进度"].includes(normalized)) return "progress";
|
||||
return null;
|
||||
}
|
||||
|
||||
function markdownCells(line: string): string[] {
|
||||
const trimmed = line.trim();
|
||||
const withoutOuterPipes = trimmed.replace(/^\|/u, "").replace(/\|$/u, "");
|
||||
return withoutOuterPipes.split("|").map((cell) => cell.trim());
|
||||
}
|
||||
|
||||
function isMarkdownTableSeparator(line: string): boolean {
|
||||
const cells = markdownCells(line);
|
||||
return cells.length > 0 && cells.every((cell) => /^:?-{3,}:?$/u.test(cell.trim()));
|
||||
}
|
||||
|
||||
function boardSectionKindFromHeading(line: string): BoardSectionKind | null {
|
||||
const normalized = line.toLowerCase();
|
||||
if (!line.trimStart().startsWith("#")) return null;
|
||||
if (normalized.includes("open") || normalized.includes("看板(open)") || normalized.includes("看板(open)") || normalized.includes("开放")) return "open";
|
||||
if (normalized.includes("closed") || normalized.includes("看板(closed)") || normalized.includes("看板(closed)") || normalized.includes("关闭") || normalized.includes("已关闭")) return "closed";
|
||||
return null;
|
||||
}
|
||||
|
||||
function extractIssueNumbers(text: string): number[] {
|
||||
const numbers: number[] = [];
|
||||
const seen = new Set<number>();
|
||||
const patterns = [/#(\d+)/g, /\/issues\/(\d+)/g];
|
||||
for (const pattern of patterns) {
|
||||
pattern.lastIndex = 0;
|
||||
let match = pattern.exec(text);
|
||||
while (match !== null) {
|
||||
const value = Number(match[1]);
|
||||
if (Number.isInteger(value) && value > 0 && !seen.has(value)) {
|
||||
seen.add(value);
|
||||
numbers.push(value);
|
||||
}
|
||||
match = pattern.exec(text);
|
||||
}
|
||||
}
|
||||
return numbers;
|
||||
}
|
||||
|
||||
function cellHasMeaningfulValue(value: string | undefined): boolean {
|
||||
if (value === undefined) return false;
|
||||
const stripped = stripMarkdownInline(value);
|
||||
if (stripped.length === 0) return false;
|
||||
return !["-", "—", "n/a", "na", "todo", "tbd", "待补", "未填", "无"].includes(stripped.toLowerCase());
|
||||
}
|
||||
|
||||
function parseBoardTables(body: string): { sections: BoardTableSection[]; warnings: BoardRowValidationWarning[] } {
|
||||
const lines = normalizeNewlines(body).split("\n");
|
||||
const sections: BoardTableSection[] = [];
|
||||
const warnings: BoardRowValidationWarning[] = [];
|
||||
let currentKind: BoardSectionKind | null = null;
|
||||
let currentHeading = "";
|
||||
let currentHeadingLine = 0;
|
||||
for (let index = 0; index < lines.length; index += 1) {
|
||||
const headingKind = boardSectionKindFromHeading(lines[index]);
|
||||
if (headingKind !== null) {
|
||||
currentKind = headingKind;
|
||||
currentHeading = lines[index].trim();
|
||||
currentHeadingLine = index + 1;
|
||||
continue;
|
||||
}
|
||||
if (currentKind === null) continue;
|
||||
if (!lines[index].trim().startsWith("|")) continue;
|
||||
const separator = lines[index + 1];
|
||||
if (separator === undefined || !separator.trim().startsWith("|") || !isMarkdownTableSeparator(separator)) continue;
|
||||
const headers = markdownCells(lines[index]);
|
||||
const columnMap = new Map<BoardRequiredColumn, number>();
|
||||
headers.forEach((header, headerIndex) => {
|
||||
const kind = boardHeaderColumnKind(header);
|
||||
if (kind !== null && !columnMap.has(kind)) columnMap.set(kind, headerIndex);
|
||||
});
|
||||
const rows: BoardTableRow[] = [];
|
||||
let rowIndex = index + 2;
|
||||
while (rowIndex < lines.length && lines[rowIndex].trim().startsWith("|")) {
|
||||
if (!isMarkdownTableSeparator(lines[rowIndex])) {
|
||||
const cells = markdownCells(lines[rowIndex]);
|
||||
const issueNumbers = extractIssueNumbers(lines[rowIndex]);
|
||||
const columns: Partial<Record<BoardRequiredColumn, string>> = {};
|
||||
for (const column of BOARD_AUDIT_REQUIRED_COLUMNS) {
|
||||
const cellIndex = columnMap.get(column);
|
||||
if (cellIndex !== undefined) columns[column] = cells[cellIndex] ?? "";
|
||||
}
|
||||
const row: BoardTableRow = {
|
||||
section: currentKind,
|
||||
lineNumber: rowIndex + 1,
|
||||
raw: lines[rowIndex],
|
||||
cells,
|
||||
issueNumbers,
|
||||
issueNumber: issueNumbers[0] ?? null,
|
||||
title: cells.find((cell) => extractIssueNumbers(cell).length > 0) ?? cells[0] ?? null,
|
||||
columns,
|
||||
};
|
||||
rows.push(row);
|
||||
if (issueNumbers.length === 0) {
|
||||
warnings.push({
|
||||
issueNumber: null,
|
||||
section: currentKind,
|
||||
lineNumber: row.lineNumber,
|
||||
kind: "missing-issue-reference",
|
||||
message: "Board table row does not contain a GitHub issue reference such as #36.",
|
||||
rowPreview: preview(row.raw),
|
||||
});
|
||||
}
|
||||
if (issueNumbers.length > 1) {
|
||||
warnings.push({
|
||||
issueNumber: row.issueNumber,
|
||||
section: currentKind,
|
||||
lineNumber: row.lineNumber,
|
||||
kind: "multiple-issue-references",
|
||||
message: "Board table row contains multiple issue references; audit uses the first number as the row key.",
|
||||
rowPreview: preview(row.raw),
|
||||
});
|
||||
}
|
||||
const missingColumns = BOARD_AUDIT_REQUIRED_COLUMNS.filter((column) => !cellHasMeaningfulValue(columns[column]));
|
||||
if (missingColumns.length > 0) {
|
||||
warnings.push({
|
||||
issueNumber: row.issueNumber,
|
||||
section: currentKind,
|
||||
lineNumber: row.lineNumber,
|
||||
kind: "missing-required-columns",
|
||||
message: "Board table row is missing branch, acceptance, related task, or progress information.",
|
||||
missingColumns,
|
||||
columns,
|
||||
rowPreview: preview(row.raw),
|
||||
});
|
||||
}
|
||||
}
|
||||
rowIndex += 1;
|
||||
}
|
||||
sections.push({
|
||||
kind: currentKind,
|
||||
heading: currentHeading,
|
||||
headingLine: currentHeadingLine,
|
||||
headerLine: index + 1,
|
||||
headers,
|
||||
rows,
|
||||
});
|
||||
index = rowIndex - 1;
|
||||
}
|
||||
return { sections, warnings };
|
||||
}
|
||||
|
||||
function boardRowsByIssue(rows: BoardTableRow[]): Map<number, BoardTableRow[]> {
|
||||
const map = new Map<number, BoardTableRow[]>();
|
||||
for (const row of rows) {
|
||||
if (row.issueNumber === null) continue;
|
||||
const list = map.get(row.issueNumber);
|
||||
if (list === undefined) map.set(row.issueNumber, [row]);
|
||||
else list.push(row);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
function ignoredIssueList(issues: BoardIssueEntry[], ignoreMap: Map<number, "known-meta" | "ignored">): BoardIgnoredIssue[] {
|
||||
return sortedIssueEntries(issues.filter((issue) => ignoreMap.has(issue.number))).map((issue) => ({
|
||||
number: issue.number,
|
||||
reason: ignoreMap.get(issue.number) ?? "ignored",
|
||||
title: issue.title,
|
||||
state: issue.state,
|
||||
url: issue.url,
|
||||
}));
|
||||
}
|
||||
|
||||
function ignoredBoardOnlyIssues(issueNumbers: number[], issueMap: Map<number, BoardIssueEntry>, ignoreMap: Map<number, "known-meta" | "ignored">): BoardIgnoredIssue[] {
|
||||
return issueNumbers
|
||||
.filter((issueNumber) => ignoreMap.has(issueNumber) && !issueMap.has(issueNumber))
|
||||
.sort((a, b) => a - b)
|
||||
.map((issueNumber) => ({ number: issueNumber, reason: ignoreMap.get(issueNumber) ?? "ignored" }));
|
||||
}
|
||||
|
||||
function issueProfileFor(issueNumber: number, requested: IssueBodyProfileOption): IssueBodyProfileName | null {
|
||||
if (requested !== "auto") return requested;
|
||||
if (issueNumber === CODE_QUEUE_BOARD_TARGET_ISSUE) return "code-queue-board";
|
||||
@@ -1652,6 +1954,172 @@ async function issueList(repo: string, token: string, state: IssueListState, lim
|
||||
};
|
||||
}
|
||||
|
||||
async function issueBoardAudit(repo: string, token: string, options: GitHubOptions): Promise<GitHubCommandResult> {
|
||||
const commandName = "issue board-audit";
|
||||
const boardIssue = await getIssue(token, repo, options.boardIssue);
|
||||
if (isGitHubError(boardIssue)) return commandError(commandName, repo, boardIssue, { boardIssue: options.boardIssue });
|
||||
const [rawOpenIssues, rawClosedIssues] = await Promise.all([
|
||||
listIssues(token, repo, "open", options.limit),
|
||||
listIssues(token, repo, "closed", options.limit),
|
||||
]);
|
||||
if (isGitHubError(rawOpenIssues)) return commandError(commandName, repo, rawOpenIssues, { phase: "list-open-issues", boardIssue: options.boardIssue, limit: options.limit });
|
||||
if (isGitHubError(rawClosedIssues)) return commandError(commandName, repo, rawClosedIssues, { phase: "list-closed-issues", boardIssue: options.boardIssue, limit: options.limit });
|
||||
|
||||
const openIssues = rawOpenIssues.filter((issue) => issue.pull_request === undefined).slice(0, options.limit).map(boardIssueEntry);
|
||||
const closedIssues = rawClosedIssues.filter((issue) => issue.pull_request === undefined).slice(0, options.limit).map(boardIssueEntry);
|
||||
const allListedIssues = [...openIssues, ...closedIssues];
|
||||
const issueMap = new Map<number, BoardIssueEntry>(allListedIssues.map((issue) => [issue.number, issue]));
|
||||
const ignoreMap = boardIgnoreMap(options);
|
||||
const parsed = parseBoardTables(boardIssue.body ?? "");
|
||||
const rowValidationWarnings = parsed.warnings.filter((warning) => warning.issueNumber === null || !ignoreMap.has(warning.issueNumber));
|
||||
const openRows = parsed.sections.filter((section) => section.kind === "open").flatMap((section) => section.rows);
|
||||
const closedRows = parsed.sections.filter((section) => section.kind === "closed").flatMap((section) => section.rows);
|
||||
const openRowMap = boardRowsByIssue(openRows);
|
||||
const closedRowMap = boardRowsByIssue(closedRows);
|
||||
const openIssueNumbers = new Set(openIssues.map((issue) => issue.number));
|
||||
const closedIssueNumbers = new Set(closedIssues.map((issue) => issue.number));
|
||||
const boardIssueNumbers = Array.from(new Set([...openRowMap.keys(), ...closedRowMap.keys()]));
|
||||
|
||||
const missingOpenIssues = sortedIssueEntries(openIssues.filter((issue) => !ignoreMap.has(issue.number) && !openRowMap.has(issue.number)));
|
||||
const closedInOpenRows = sortedIssueEntries(closedIssues.filter((issue) => !ignoreMap.has(issue.number) && openRowMap.has(issue.number))).map((issue) => ({
|
||||
...issue,
|
||||
rows: (openRowMap.get(issue.number) ?? []).map((row) => ({ lineNumber: row.lineNumber, rowPreview: preview(row.raw) })),
|
||||
}));
|
||||
const missingClosedRows = sortedIssueEntries(closedIssues.filter((issue) => !ignoreMap.has(issue.number) && !closedRowMap.has(issue.number)));
|
||||
const openInClosedRows = sortedIssueEntries(openIssues.filter((issue) => !ignoreMap.has(issue.number) && closedRowMap.has(issue.number))).map((issue) => ({
|
||||
...issue,
|
||||
rows: (closedRowMap.get(issue.number) ?? []).map((row) => ({ lineNumber: row.lineNumber, rowPreview: preview(row.raw) })),
|
||||
}));
|
||||
const staleOpenRows = Array.from(openRowMap.entries())
|
||||
.filter(([issueNumber]) => !ignoreMap.has(issueNumber) && !openIssueNumbers.has(issueNumber))
|
||||
.map(([issueNumber, rows]) => ({
|
||||
issueNumber,
|
||||
knownState: closedIssueNumbers.has(issueNumber) ? "closed" : "not-in-listed-window",
|
||||
rows: rows.map((row) => ({ lineNumber: row.lineNumber, rowPreview: preview(row.raw) })),
|
||||
}))
|
||||
.sort((a, b) => a.issueNumber - b.issueNumber);
|
||||
const boardOnlyRows = boardIssueNumbers
|
||||
.filter((issueNumber) => !ignoreMap.has(issueNumber) && !issueMap.has(issueNumber))
|
||||
.sort((a, b) => a - b)
|
||||
.map((issueNumber) => ({
|
||||
issueNumber,
|
||||
sections: [
|
||||
...(openRowMap.has(issueNumber) ? ["open"] : []),
|
||||
...(closedRowMap.has(issueNumber) ? ["closed"] : []),
|
||||
],
|
||||
rows: [...(openRowMap.get(issueNumber) ?? []), ...(closedRowMap.get(issueNumber) ?? [])].map((row) => ({
|
||||
section: row.section,
|
||||
lineNumber: row.lineNumber,
|
||||
rowPreview: preview(row.raw),
|
||||
})),
|
||||
}));
|
||||
const ignoredIssues = [
|
||||
...ignoredIssueList(allListedIssues, ignoreMap),
|
||||
...ignoredBoardOnlyIssues(boardIssueNumbers, issueMap, ignoreMap),
|
||||
].sort((a, b) => a.number - b.number);
|
||||
const recommendedActions = [
|
||||
...missingOpenIssues.map((issue) => ({
|
||||
action: "add-open-row",
|
||||
issueNumber: issue.number,
|
||||
title: issue.title,
|
||||
section: "open",
|
||||
reason: "GitHub issue is open but no #20 OPEN table row was found.",
|
||||
})),
|
||||
...closedInOpenRows.map((issue) => ({
|
||||
action: "move-open-row-to-closed",
|
||||
issueNumber: issue.number,
|
||||
title: issue.title,
|
||||
reason: "GitHub issue is closed but still appears in the #20 OPEN table.",
|
||||
})),
|
||||
...missingClosedRows.map((issue) => ({
|
||||
action: "add-closed-row",
|
||||
issueNumber: issue.number,
|
||||
title: issue.title,
|
||||
section: "closed",
|
||||
reason: "GitHub issue is closed but no #20 CLOSED table row was found.",
|
||||
})),
|
||||
...openInClosedRows.map((issue) => ({
|
||||
action: "move-closed-row-to-open",
|
||||
issueNumber: issue.number,
|
||||
title: issue.title,
|
||||
reason: "GitHub issue is open but appears in the #20 CLOSED table.",
|
||||
})),
|
||||
...rowValidationWarnings.map((warning) => ({
|
||||
action: "fill-board-row-fields",
|
||||
issueNumber: warning.issueNumber,
|
||||
section: warning.section,
|
||||
lineNumber: warning.lineNumber,
|
||||
reason: warning.message,
|
||||
missingColumns: warning.missingColumns ?? [],
|
||||
})),
|
||||
];
|
||||
|
||||
return {
|
||||
ok: true,
|
||||
command: commandName,
|
||||
repo,
|
||||
dryRun: true,
|
||||
planned: true,
|
||||
readOnly: true,
|
||||
boardIssue: {
|
||||
number: boardIssue.number,
|
||||
title: boardIssue.title,
|
||||
state: boardIssue.state,
|
||||
url: boardIssue.html_url,
|
||||
bodyChars: (boardIssue.body ?? "").length,
|
||||
updatedAt: boardIssue.updated_at ?? null,
|
||||
},
|
||||
config: {
|
||||
limit: options.limit,
|
||||
knownMetaIssues: mergedKnownMetaIssues(options),
|
||||
ignoredIssues: options.ignoredIssues,
|
||||
requiredColumns: BOARD_AUDIT_REQUIRED_COLUMNS.slice(),
|
||||
},
|
||||
summary: {
|
||||
openIssues: openIssues.length,
|
||||
closedIssues: closedIssues.length,
|
||||
openRows: openRows.length,
|
||||
closedRows: closedRows.length,
|
||||
missingOpenIssues: missingOpenIssues.length,
|
||||
closedInOpenRows: closedInOpenRows.length,
|
||||
missingClosedRows: missingClosedRows.length,
|
||||
openInClosedRows: openInClosedRows.length,
|
||||
rowValidationWarnings: rowValidationWarnings.length,
|
||||
ignoredIssues: ignoredIssues.length,
|
||||
boardOnlyRows: boardOnlyRows.length,
|
||||
staleOpenRows: staleOpenRows.length,
|
||||
},
|
||||
sections: parsed.sections.map((section) => ({
|
||||
kind: section.kind,
|
||||
heading: section.heading,
|
||||
headingLine: section.headingLine,
|
||||
headerLine: section.headerLine,
|
||||
headers: section.headers,
|
||||
rows: section.rows.length,
|
||||
issueNumbers: section.rows.flatMap((row) => row.issueNumbers),
|
||||
})),
|
||||
missingOpenIssues,
|
||||
closedInOpenRows,
|
||||
missingClosedRows,
|
||||
openInClosedRows,
|
||||
staleOpenRows,
|
||||
boardOnlyRows,
|
||||
rowValidationWarnings,
|
||||
ignoredIssues,
|
||||
recommendedActions,
|
||||
request: {
|
||||
method: "GET",
|
||||
paths: [
|
||||
`/repos/{owner}/{repo}/issues/${options.boardIssue}`,
|
||||
"/repos/{owner}/{repo}/issues?state=open",
|
||||
"/repos/{owner}/{repo}/issues?state=closed",
|
||||
],
|
||||
query: { per_page: options.limit },
|
||||
},
|
||||
note: "Read-only board audit; no issue body was edited, no issue was closed, and no comments were written.",
|
||||
};
|
||||
}
|
||||
|
||||
async function issueCreate(repo: string, token: string, options: GitHubOptions): Promise<GitHubCommandResult> {
|
||||
if (options.title === undefined) throw new Error("issue create requires --title <title>");
|
||||
const body = readBodyFile(options.bodyFile, "issue create");
|
||||
@@ -2368,6 +2836,7 @@ export function ghHelp(): unknown {
|
||||
"bun scripts/cli.ts gh issue delete <number> [unsupported: use close]",
|
||||
"bun scripts/cli.ts gh issue scan-escape [--repo owner/name] [--limit N] [--dry-run]",
|
||||
"bun scripts/cli.ts gh issue cleanup-plan [--repo owner/name] [--limit N] [--dry-run]",
|
||||
"bun scripts/cli.ts gh issue board-audit [--repo owner/name] [--board-issue 20] [--limit N] [--known-meta-issue N[,N...]] [--ignore-issue N[,N...]] [--dry-run]",
|
||||
"bun scripts/cli.ts gh pr list [--repo owner/name] [--limit N] [--json number,title,state,url,updatedAt,createdAt,author,head,base,draft]",
|
||||
"bun scripts/cli.ts gh pr view <number> [--repo owner/name] [--json body,title,state,head,base,draft]",
|
||||
"bun scripts/cli.ts gh pr create --title <title> --body-file <file>|--body <text> --base <branch> --head <branch> [--repo owner/name] [--draft] [--dry-run]",
|
||||
@@ -2393,6 +2862,7 @@ export function ghHelp(): unknown {
|
||||
"When staging a body file from a shell, use a quoted heredoc such as cat <<'EOF' > /tmp/body.md so backticks and backslashes are not expanded before --body-file reads the file.",
|
||||
"For JSON request bodies in other CLI namespaces, prefer --body-file or --body-stdin over long inline shell arguments; GitHub Markdown writes intentionally use --body-file only.",
|
||||
"issue scan-escape classifies literal \\n findings as suspected-pollution, explanatory-mention, or risk, and emits cleanupSuggestions with body/comment ids plus diff-like previews. cleanup-plan is an alias that remains dry-run/read-only.",
|
||||
"issue board-audit is read-only and defaults to repo pikasTech/unidesk plus board issue #20. It compares GitHub open/closed issue lists with the board OPEN/CLOSED tables and reports missingOpenIssues, closedInOpenRows, missingClosedRows, rowValidationWarnings, ignoredIssues, and recommendedActions. #20 and #24 are known meta issues by default.",
|
||||
"issue edit 24 --notify-claudeqq-brief-diff reads the old issue body, PATCHes the new body, and sends only newly added '## 更新 ... 北京时间' sections to ClaudeQQ; ClaudeQQ failure does not roll back GitHub.",
|
||||
"Commander brief ClaudeQQ defaults to private target 645275593 through backend-core /api/microservices/claudeqq/proxy; UNIDESK_COMMANDER_BRIEF_CLAUDEQQ_* env vars can override target, base URL, timeout, and enabled state.",
|
||||
"comment delete is supported because GitHub supports deleting issue comments; issue/pr hard delete is unsupported and close is the lifecycle alternative.",
|
||||
@@ -2437,6 +2907,10 @@ export async function runGhCommand(args: string[]): Promise<GitHubCommandResult
|
||||
const command = [top, sub].filter((value): value is string => value !== undefined).join(" ") || "gh";
|
||||
return validationError(command, options.repo, "--allow-short-body, --expect-updated-at, --expect-body-sha, and --body-profile are only supported by gh issue update/edit");
|
||||
}
|
||||
if ((optionWasProvided(args, "--board-issue") || optionWasProvided(args, "--known-meta-issue") || optionWasProvided(args, "--ignore-issue")) && !(top === "issue" && sub === "board-audit")) {
|
||||
const command = [top, sub].filter((value): value is string => value !== undefined).join(" ") || "gh";
|
||||
return validationError(command, options.repo, "--board-issue, --known-meta-issue, and --ignore-issue are only supported by gh issue board-audit");
|
||||
}
|
||||
if (optionWasProvided(args, "--label") && !(top === "issue" && sub === "create")) {
|
||||
const command = [top, sub].filter((value): value is string => value !== undefined).join(" ") || "gh";
|
||||
return validationError(command, options.repo, "--label is only supported by gh issue create");
|
||||
@@ -2471,6 +2945,12 @@ export async function runGhCommand(args: string[]): Promise<GitHubCommandResult
|
||||
if (missing !== null || token === null) return missing ?? authRequired(options.repo, commandName, { present: false, source: null, ghFallbackAttempted: true });
|
||||
return issueScanEscape(options.repo, token, options.limit, options.dryRun || sub === "cleanup-plan", commandName);
|
||||
}
|
||||
if (sub === "board-audit") {
|
||||
const { token, probe } = resolveToken(true);
|
||||
const missing = authRequired(options.repo, "issue board-audit", probe);
|
||||
if (missing !== null || token === null) return missing ?? authRequired(options.repo, "issue board-audit", { present: false, source: null, ghFallbackAttempted: true });
|
||||
return issueBoardAudit(options.repo, token, options);
|
||||
}
|
||||
if (options.dryRun) {
|
||||
if (sub === "create") return issueCreate(options.repo, "", options);
|
||||
if (sub === "edit") {
|
||||
|
||||
Reference in New Issue
Block a user