From 5462aca6d75ee45f04495f272ade1f697aabe984 Mon Sep 17 00:00:00 2001 From: Lyon <88232613+pikasTech@users.noreply.github.com> Date: Mon, 22 Jun 2026 15:40:39 +0800 Subject: [PATCH] fix: render gh issue list as table (#663) Co-authored-by: Codex --- scripts/src/gh.ts | 47 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/scripts/src/gh.ts b/scripts/src/gh.ts index 4b14b402..d5229677 100644 --- a/scripts/src/gh.ts +++ b/scripts/src/gh.ts @@ -6524,6 +6524,50 @@ function issueListNextCommand(repo: string, state: IssueListState, limit: number return parts.join(" "); } +function issueListLabelText(value: unknown): string { + if (!Array.isArray(value)) return ghText(value); + const labels = value + .map((item) => typeof item === "string" ? item : isRecord(item) ? ghText(item.name) : ghText(item)) + .filter((item) => item !== "-"); + return labels.length === 0 ? "-" : labels.join(","); +} + +function withIssueListRendered(result: GitHubCommandResult): GitHubCommandResult { + return { + ...result, + contentType: "text/plain", + renderedText: renderIssueListTable(result), + }; +} + +function renderIssueListTable(result: GitHubCommandResult): string { + const issues = Array.isArray(result.issues) ? result.issues.map((item) => record(item)) : []; + const rows = issues.map((issue) => [ + issue.number === undefined ? "-" : `#${ghText(issue.number)}`, + ghText(issue.state), + ghShort(ghText(issue.updatedAt), 19), + ghShort(issueListLabelText(issue.labels), 32), + ghShort(ghText(issue.title), 96), + ]); + const next = isRecord(result.next) ? result.next : {}; + const lines = [ + "gh issue list (observed)", + "", + ghTable(["ISSUE", "STATE", "UPDATED", "LABELS", "TITLE"], rows), + "", + "Summary:", + ` repo=${ghText(result.repo)} state=${ghText(result.state)} count=${ghText(result.count)} raw=${ghText(result.rawCount)} hasMore=${ghText(result.hasMore)}`, + ` search=${ghText(result.search)} labels=${issueListLabelText(result.labels)} titlePrefix=${ghText(result.titlePrefix)}`, + ]; + if (result.searchTotalCount !== undefined) lines.push(` searchTotal=${ghText(result.searchTotalCount)} incomplete=${ghText(result.searchIncomplete)}`); + if (typeof next.command === "string" && next.command.length > 0) { + lines.push("", "Next:", ` ${next.command}`); + } + lines.push("", "Disclosure:"); + lines.push(" default view is a bounded table; use --json for selected fields or --full/--raw for structured pagination and request metadata."); + return lines.join("\n"); +} + async function issueList(repo: string, token: string, state: IssueListState, limit: number, jsonFields: IssueListJsonField[] | undefined, search?: string, labels: string[] = [], noDump = false, titlePrefix?: string): Promise { const normalizedSearch = String(search ?? "").trim(); const normalizedTitlePrefix = String(titlePrefix ?? "").trim(); @@ -6535,7 +6579,7 @@ async function issueList(repo: string, token: string, state: IssueListState, lim ? listedIssues.filter((issue) => issue.title.startsWith(normalizedTitlePrefix)) : listedIssues; const fields = jsonFields ?? ISSUE_LIST_JSON_FIELDS.slice(); - return { + const payload: GitHubCommandResult = { ok: true, command: "issue list", repo, @@ -6592,6 +6636,7 @@ async function issueList(repo: string, token: string, state: IssueListState, lim }, note: "GitHub's issues endpoint may include pull requests; this command filters pull requests from .issues.", }; + return jsonFields === undefined && !noDump ? withIssueListRendered(payload) : payload; } async function issueBoardAudit(repo: string, token: string, options: GitHubOptions): Promise {