From a4a81c0c2c1425a056129db0eee7203350f3352f Mon Sep 17 00:00:00 2001 From: Codex Date: Sun, 21 Jun 2026 15:47:57 +0000 Subject: [PATCH] fix: render gh pr create as table --- scripts/src/gh.ts | 50 ++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 47 insertions(+), 3 deletions(-) diff --git a/scripts/src/gh.ts b/scripts/src/gh.ts index 37dbad0f..d1eec620 100644 --- a/scripts/src/gh.ts +++ b/scripts/src/gh.ts @@ -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(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 { let bodySource: { body: string; bodySource: Record }; try {