Merge pull request #615 from pikasTech/fix/gh-issue-create-table-20260621

fix: render gh issue create as table
This commit is contained in:
Lyon
2026-06-22 00:01:36 +08:00
committed by GitHub
+42 -3
View File
@@ -6555,7 +6555,7 @@ async function issueCreate(repo: string, token: string, options: GitHubOptions):
}, "issue create");
const labels = options.labels;
if (options.dryRun) {
return {
return withIssueCreateRendered({
ok: true,
command: "issue create",
repo,
@@ -6564,7 +6564,7 @@ async function issueCreate(repo: string, token: string, options: GitHubOptions):
title: options.title,
labels,
...writeBodyPlan("issue create", repo, body, bodySource, { title: options.title, labels }),
};
});
}
const { owner, name } = repoParts(repo);
const payload: Record<string, unknown> = { title: options.title, body };
@@ -6581,7 +6581,46 @@ async function issueCreate(repo: string, token: string, options: GitHubOptions):
missingLabels,
});
}
return { ok: true, command: "issue create", repo, issue: issueSummary(issue), labels, bodySource, rest: true };
return withIssueCreateRendered({ ok: true, command: "issue create", repo, issue: issueSummary(issue), labels, bodySource, rest: true });
}
function withIssueCreateRendered(result: GitHubCommandResult): GitHubCommandResult {
return {
...result,
contentType: "text/plain",
renderedText: renderIssueCreateTable(result),
};
}
function renderIssueCreateTable(result: GitHubCommandResult): string {
const issue = isRecord(result.issue) ? result.issue : {};
const number = ghText(issue.number ?? result.number);
const title = ghText(issue.title ?? result.title);
const status = result.dryRun === true ? "dry-run" : "created";
const labels = Array.isArray(result.labels) ? result.labels.map(String).join(",") : ghText(result.labels);
const lines = [
`gh issue create (${status})`,
"",
ghTable(["ISSUE", "STATUS", "LABELS", "TITLE"], [[
number === "-" ? "-" : `#${number}`,
status,
ghShort(labels, 40),
ghShort(title, 96),
]]),
"",
"Summary:",
` repo=${ghText(result.repo)} url=${ghText(issue.url ?? result.url)}`,
"",
"Next:",
];
if (status === "created" && number !== "-") {
lines.push(` bun scripts/cli.ts gh issue view ${number} --repo ${ghText(result.repo)}`);
} else {
lines.push(" rerun without --dry-run to create the issue");
}
lines.push("", "Disclosure:");
lines.push(" default view is a bounded table; use gh issue view --full for structured metadata.");
return lines.join("\n");
}
async function issuePatch(repo: string, token: string, issueNumber: number, options: GitHubOptions): Promise<GitHubCommandResult> {