fix: render gh pr create as table
This commit is contained in:
+47
-3
@@ -5543,7 +5543,7 @@ async function prCreate(repo: string, token: string, options: GitHubOptions): Pr
|
||||
const body = bodySource.body;
|
||||
const planned = prCreatePlannedOperation(repo, options, body, bodySource.bodySource);
|
||||
if (options.dryRun) {
|
||||
return {
|
||||
return withPrCreateRendered({
|
||||
ok: true,
|
||||
command: "pr create",
|
||||
repo,
|
||||
@@ -5551,7 +5551,7 @@ async function prCreate(repo: string, token: string, options: GitHubOptions): Pr
|
||||
planned: true,
|
||||
draft: options.draft,
|
||||
...planned,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
const repoResult = await repoInfo(token, repo);
|
||||
@@ -5581,7 +5581,7 @@ async function prCreate(repo: string, token: string, options: GitHubOptions): Pr
|
||||
};
|
||||
const pr = await githubRequest<GitHubPullRequest>(token, "POST", `/repos/${owner}/${name}/pulls`, payload);
|
||||
if (isGitHubError(pr)) return commandError("pr create", repo, pr, { base: options.base, head: options.head, planned });
|
||||
return {
|
||||
return withPrCreateRendered({
|
||||
ok: true,
|
||||
command: "pr create",
|
||||
repo,
|
||||
@@ -5603,9 +5603,53 @@ async function prCreate(repo: string, token: string, options: GitHubOptions): Pr
|
||||
bodyChars: body.length,
|
||||
},
|
||||
rest: true,
|
||||
});
|
||||
}
|
||||
|
||||
function withPrCreateRendered(result: GitHubCommandResult): GitHubCommandResult {
|
||||
return {
|
||||
...result,
|
||||
contentType: "text/plain",
|
||||
renderedText: renderPrCreateTable(result),
|
||||
};
|
||||
}
|
||||
|
||||
function renderPrCreateTable(result: GitHubCommandResult): string {
|
||||
const pr = isRecord(result.pr) ? result.pr : {};
|
||||
const request = isRecord(result.request) ? result.request : {};
|
||||
const number = ghText(pr.number ?? result.number ?? result.pr);
|
||||
const title = ghText(pr.title ?? request.title ?? result.title);
|
||||
const base = ghText(isRecord(pr.base) ? pr.base.ref : request.base ?? result.base);
|
||||
const head = ghText(isRecord(pr.head) ? pr.head.ref : request.head ?? result.head);
|
||||
const status = result.dryRun === true ? "dry-run" : "created";
|
||||
const rows = [[
|
||||
number === "-" ? "-" : `#${number}`,
|
||||
status,
|
||||
base,
|
||||
head,
|
||||
ghText(request.draft ?? result.draft),
|
||||
ghShort(title, 80),
|
||||
]];
|
||||
const lines = [
|
||||
`gh pr create (${status})`,
|
||||
"",
|
||||
ghTable(["PR", "STATUS", "BASE", "HEAD", "DRAFT", "TITLE"], rows),
|
||||
"",
|
||||
"Summary:",
|
||||
` repo=${ghText(result.repo)} url=${ghText(pr.url ?? pr.html_url ?? result.url)}`,
|
||||
"",
|
||||
"Next:",
|
||||
];
|
||||
if (status === "created" && number !== "-") {
|
||||
lines.push(` bun scripts/cli.ts gh pr preflight ${number} --repo ${ghText(result.repo)}`);
|
||||
} else {
|
||||
lines.push(" rerun without --dry-run to create the PR");
|
||||
}
|
||||
lines.push("", "Disclosure:");
|
||||
lines.push(" default view is a bounded table; use gh pr view/preflight --full for structured metadata.");
|
||||
return lines.join("\n");
|
||||
}
|
||||
|
||||
async function prComment(repo: string, token: string, issueNumber: number, options: GitHubOptions): Promise<GitHubCommandResult> {
|
||||
let bodySource: { body: string; bodySource: Record<string, unknown> };
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user