fix: reduce noise for gh issue view comments

This commit is contained in:
Codex
2026-07-04 12:21:29 +00:00
parent e7749113d8
commit efb205aa39
4 changed files with 65 additions and 8 deletions
+43 -7
View File
@@ -10,6 +10,10 @@ import { commentSummary, compactCommentSummary, compactIssueViewCommentSummary }
import { GITHUB_REST_PAGE_SIZE } from "./types";
import type { GitHubCommandResult, GitHubComment, GitHubErrorPayload, GitHubIssue, GitHubIssueListPage, GitHubIssueListResult, GitHubIssueSearchResponse, IssueListState, IssueViewJsonField } from "./types";
function preferredIssueCommentsCommand(repo: string, issueNumber: number): string {
return `bun scripts/cli.ts gh issue comments ${issueNumber} --repo ${repo}`;
}
export async function listIssueComments(token: string, repo: string, issueNumber: number, options: { page?: number; perPage?: number } = {}): Promise<GitHubComment[] | GitHubErrorPayload> {
const { owner, name } = repoParts(repo);
const params = new URLSearchParams({
@@ -133,19 +137,50 @@ export function selectedIssueJson(issue: GitHubIssue, comments: GitHubComment[]
return selected;
}
function issueCommentsCompatibility(repo: string, issueNumber: number, comments: GitHubComment[] | null, includeFullCommentBodies: boolean): Record<string, unknown> {
const preferredCommand = preferredIssueCommentsCommand(repo, issueNumber);
return {
commentsCompacted: comments !== null && !includeFullCommentBodies,
commentBodiesOmitted: comments !== null && !includeFullCommentBodies,
fullCommentBodiesIncluded: comments !== null && includeFullCommentBodies,
commentsPath: comments === null ? null : ".data.json.comments",
preferredCommand: comments === null ? null : preferredCommand,
migrationHint: comments === null
? null
: "For bounded recent comment progress, prefer gh issue comments <number>; gh issue view --json comments remains the legacy compatibility path.",
readCommands: {
...(comments !== null && !includeFullCommentBodies ? issueCommentReadCommands(repo, issueNumber) : {}),
...(comments === null ? {} : { preferred: preferredCommand }),
},
};
}
export async function issueRead(repo: string, token: string, issueNumber: number, jsonFields: IssueViewJsonField[] | undefined, commandName = "issue read", disclosure: Record<string, unknown> | null = null, options: { includeFullCommentBodies?: boolean } = {}): Promise<GitHubCommandResult> {
const issue = await getIssue(token, repo, issueNumber);
if (isGitHubError(issue)) return commandError(commandName, repo, issue, { issueNumber });
const needsComments = jsonFields === undefined || jsonFields.includes("comments");
const includeBody = jsonFields === undefined || jsonFields.includes("body");
const requestedCommentsField = jsonFields?.includes("comments") === true;
const includeFullCommentBodies = options.includeFullCommentBodies === true;
const comments = needsComments ? await listIssueComments(token, repo, issueNumber) : null;
if (isGitHubError(comments)) return commandError(commandName, repo, comments, { issueNumber, issue: issueSummary(issue, { includeBody, includePreview: false }) });
const commentsCompatibility = issueCommentsCompatibility(repo, issueNumber, comments, includeFullCommentBodies);
return {
ok: true,
command: commandName,
repo,
...(disclosure === null ? {} : { disclosure }),
...((disclosure === null && !requestedCommentsField) ? {} : {
disclosure: {
...(disclosure ?? {}),
...(requestedCommentsField ? {
preferredCommand: commentsCompatibility.preferredCommand,
commentsPath: commentsCompatibility.commentsPath,
legacyCompatibilityPath: ".data.json.comments",
migrationHint: commentsCompatibility.migrationHint,
boundedAlternative: "gh issue comments returns a bounded recent-comment summary and is the preferred human/operator path.",
} : {}),
},
}),
issue: issueSummary(issue, { includeBody, includePreview: false }),
codeQueueBoardHint: codeQueueBoardCommanderBriefHint(issueNumber, issue.body ?? ""),
...(comments === null || jsonFields !== undefined ? {} : { comments: comments.map(includeFullCommentBodies ? commentSummary : compactCommentSummary) }),
@@ -155,13 +190,10 @@ export async function issueRead(repo: string, token: string, issueNumber: number
compatibility: {
legacyJsonBodyPath: includeBody ? ".data.issue.body" : null,
bodyOmitted: !includeBody,
commentsCompacted: comments !== null && !includeFullCommentBodies,
commentBodiesOmitted: comments !== null && !includeFullCommentBodies,
fullCommentBodiesIncluded: comments !== null && includeFullCommentBodies,
commentsPath: comments === null ? null : ".data.json.comments",
...commentsCompatibility,
readCommands: {
...(includeBody ? {} : issueBodyReadCommands(repo, issueNumber)),
...(comments !== null && !includeFullCommentBodies ? issueCommentReadCommands(repo, issueNumber) : {}),
...recordOrEmpty(commentsCompatibility.readCommands),
},
},
}),
@@ -217,7 +249,7 @@ export async function issueComments(repo: string, token: string, issueNumber: nu
nestedIssueViewCommentsPath: ".data.json.comments",
},
readCommands: {
self: `bun scripts/cli.ts gh issue comments ${issueNumber} --repo ${repo}`,
self: preferredIssueCommentsCommand(repo, issueNumber),
full: `bun scripts/cli.ts gh issue comments ${issueNumber} --repo ${repo} --limit ${boundedLimit} --full`,
raw: `bun scripts/cli.ts gh issue comments ${issueNumber} --repo ${repo} --limit ${boundedLimit} --raw`,
comment: `bun scripts/cli.ts gh issue comment view <commentId> --repo ${repo} --full`,
@@ -225,3 +257,7 @@ export async function issueComments(repo: string, token: string, issueNumber: nu
},
};
}
function recordOrEmpty(value: unknown): Record<string, unknown> {
return value !== null && typeof value === "object" && !Array.isArray(value) ? value as Record<string, unknown> : {};
}