feat: add bounded PR review drilldown
This commit is contained in:
@@ -50,6 +50,8 @@ function renderGhDefaultText(result: GitHubCommandResult): string {
|
||||
if (isPrReadResult(result)) return renderPrView(result);
|
||||
if (command === "pr list") return renderPrList(result);
|
||||
if (command === "pr files" || command === "pr diff --stat") return renderPrFiles(result);
|
||||
if (command === "pr review-plan") return renderPrReviewPlan(result);
|
||||
if (command === "pr diff" && isRecord(result.file)) return renderPrDiffFile(result);
|
||||
if (command.includes("comment")) return renderCommentResult(result);
|
||||
if (command === "auth status") return renderAuthStatus(result);
|
||||
if (command.startsWith("repo ")) return renderRepoResult(result);
|
||||
@@ -235,6 +237,83 @@ function renderPrFiles(result: GitHubCommandResult): string {
|
||||
return lines.join("\n");
|
||||
}
|
||||
|
||||
function renderPrReviewPlan(result: GitHubCommandResult): string {
|
||||
const files = arrayOfRecords(result.files);
|
||||
const rows = files.slice(0, 40).map((file) => {
|
||||
const patch = record(file.patch);
|
||||
return [
|
||||
ghText(file.index),
|
||||
ghShort(ghText(file.filename), 72),
|
||||
ghText(file.status),
|
||||
ghText(file.additions),
|
||||
ghText(file.deletions),
|
||||
ghText(patch.hunks),
|
||||
ghText(patch.lines),
|
||||
ghText(patch.defaultTruncated),
|
||||
];
|
||||
});
|
||||
const summary = record(result.summary);
|
||||
const truncation = record(result.truncation);
|
||||
const drillDown = files
|
||||
.map((file) => record(file.drillDown).patch)
|
||||
.filter((command): command is string => typeof command === "string")
|
||||
.slice(0, 40);
|
||||
const next = record(result.next);
|
||||
const lines = [
|
||||
"gh pr review-plan (observed)",
|
||||
"",
|
||||
ghTable(["#", "FILE", "STATUS", "ADD", "DEL", "HUNKS", "PATCH_LINES", "PATCH_TRUNC"], rows),
|
||||
"",
|
||||
"Summary:",
|
||||
` repo=${ghText(result.repo)} pr=#${ghText(record(result.pullRequest).number)} files=${ghText(summary.files)} returned=${ghText(result.filesReturned)} truncated=${ghText(truncation.truncated)}`,
|
||||
` additions=${ghText(summary.additions)} deletions=${ghText(summary.deletions)} changes=${ghText(summary.changes)}`,
|
||||
"",
|
||||
"Next:",
|
||||
];
|
||||
if (drillDown.length > 0) lines.push(...drillDown.map((command, index) => ` [${index + 1}] ${command}`));
|
||||
else lines.push(` ${ghText(next.metadata)}`);
|
||||
if (typeof next.files === "string") lines.push(` ${next.files}`);
|
||||
lines.push("", "Disclosure:", " default review-plan is a bounded changed-file index; it omits patch bodies and prints per-file drill-down commands.");
|
||||
return lines.join("\n");
|
||||
}
|
||||
|
||||
function renderPrDiffFile(result: GitHubCommandResult): string {
|
||||
const file = record(result.file);
|
||||
const patch = record(result.patch);
|
||||
const selectedHunk = record(patch.hunk);
|
||||
const patchLines = Array.isArray(patch.lines) ? patch.lines.filter((line): line is string => typeof line === "string") : [];
|
||||
const next = record(result.next);
|
||||
const lines = [
|
||||
"gh pr diff (observed)",
|
||||
"",
|
||||
ghTable(["FILE", "STATUS", "ADD", "DEL", "HUNKS", "SELECTED", "LINES", "SHOWN", "TRUNC"], [[
|
||||
ghShort(ghText(file.filename), 72),
|
||||
ghText(file.status),
|
||||
ghText(file.additions),
|
||||
ghText(file.deletions),
|
||||
ghText(file.hunks),
|
||||
ghText(selectedHunk.index ?? "file"),
|
||||
ghText(patch.linesTotal),
|
||||
ghText(patch.linesShown),
|
||||
ghText(patch.truncated),
|
||||
]]),
|
||||
"",
|
||||
"Patch:",
|
||||
...patchLines.map((line) => ` ${line}`),
|
||||
"",
|
||||
"Summary:",
|
||||
` repo=${ghText(result.repo)} pr=#${ghText(record(result.pullRequest).number)} file=${ghText(file.filename)} redactions=${ghText(patch.redactions)} rawDiffIncluded=${ghText(result.rawDiffIncluded)}`,
|
||||
"",
|
||||
"Next:",
|
||||
` ${ghText(next.reviewPlan)}`,
|
||||
` ${ghText(next.nextHunk ?? next.fullFilePatch)}`,
|
||||
"",
|
||||
"Disclosure:",
|
||||
" default diff output is a bounded patch excerpt; use --hunk N for one hunk or --full/--raw for explicit structured full-patch disclosure.",
|
||||
];
|
||||
return lines.join("\n");
|
||||
}
|
||||
|
||||
function renderCommentResult(result: GitHubCommandResult): string {
|
||||
const comment = record(result.comment);
|
||||
const status = result.dryRun === true ? "dry-run" : result.deleted === true ? "deleted" : result.ok ? "ok" : "failed";
|
||||
|
||||
Reference in New Issue
Block a user