diff --git a/scripts/src/gh.ts b/scripts/src/gh.ts index d5229677..b36bec78 100644 --- a/scripts/src/gh.ts +++ b/scripts/src/gh.ts @@ -7112,6 +7112,44 @@ async function issueEdit(repo: string, token: string, issueNumber: number, optio }; } +function withIssueCommentCreateRendered(result: GitHubCommandResult): GitHubCommandResult { + return { + ...result, + contentType: "text/plain", + renderedText: renderIssueCommentCreateTable(result), + }; +} + +function renderIssueCommentCreateTable(result: GitHubCommandResult): string { + const comment = isRecord(result.comment) ? result.comment : {}; + const readCommands = isRecord(result.readCommands) ? result.readCommands : {}; + const status = result.dryRun === true ? "dry-run" : "created"; + const issueNumber = ghText(result.issueNumber); + const commentId = ghText(comment.id ?? result.commentId); + const sourceKind = isRecord(result.bodySource) ? result.bodySource.kind : result.source; + const lines = [ + `gh issue comment create (${status})`, + "", + ghTable(["ISSUE", "COMMENT", "STATUS", "BODY", "URL"], [[ + issueNumber === "-" ? "-" : `#${issueNumber}`, + commentId, + status, + `${ghText(result.bodyChars ?? comment.bodyChars)} chars`, + ghShort(ghText(comment.url ?? result.url), 96), + ]]), + "", + "Summary:", + ` repo=${ghText(result.repo)} source=${ghText(sourceKind)} bodySha=${ghText(result.bodySha ?? comment.bodySha)}`, + "", + "Next:", + ` ${ghText(readCommands.comments ?? readCommands.full ?? readCommands.raw)}`, + "", + "Disclosure:", + " default view is a bounded table; use --full/--raw or the read command for full comment metadata/body.", + ]; + return lines.join("\n"); +} + async function issueComment(repo: string, token: string, issueNumber: number, options: GitHubOptions): Promise { let bodyInput: { body: string; bodySource: Record }; try { @@ -7121,7 +7159,7 @@ async function issueComment(repo: string, token: string, issueNumber: number, op } const { body, bodySource } = bodyInput; if (options.dryRun) { - return { + return withIssueCommentCreateRendered({ ok: true, command: "issue comment create", repo, @@ -7130,12 +7168,12 @@ async function issueComment(repo: string, token: string, issueNumber: number, op issueNumber, readCommands: issueCommentReadCommands(repo, issueNumber), ...writeBodyPlan("issue comment create", repo, body, bodySource, { issueNumber }), - }; + }); } const { owner, name } = repoParts(repo); const comment = await githubRequest(token, "POST", `/repos/${owner}/${name}/issues/${issueNumber}/comments`, { body }); if (isGitHubError(comment)) return commandError("issue comment", repo, comment, { issueNumber }); - return { + return withIssueCommentCreateRendered({ ok: true, command: "issue comment create", repo, @@ -7148,7 +7186,7 @@ async function issueComment(repo: string, token: string, issueNumber: number, op source: String(bodySource.kind ?? "unknown"), readCommands: issueCommentReadCommands(repo, issueNumber), rest: true, - }; + }); } async function commentPatch(repo: string, token: string, ownerKind: "issue" | "pr", commentId: number, options: GitHubOptions, commandName?: string): Promise {