fix: render gh issue list as table (#663)
Co-authored-by: Codex <codex@noreply.local>
This commit is contained in:
+46
-1
@@ -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<GitHubCommandResult> {
|
||||
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<GitHubCommandResult> {
|
||||
|
||||
Reference in New Issue
Block a user