fix(cli): expose merged PR closeout fields
This commit is contained in:
+33
-11
@@ -21,7 +21,7 @@ const BOARD_ROW_UPSERT_TEXT_FIELDS = ["category", "branch", "tasks", "summary",
|
||||
const ISSUE_VIEW_JSON_FIELDS = ["body", "title", "state", "comments", "number", "url", "author", "createdAt", "updatedAt"] as const;
|
||||
const ISSUE_LIST_JSON_FIELDS = ["number", "title", "state", "url", "updatedAt", "createdAt", "author", "labels"] as const;
|
||||
const PR_LIST_JSON_FIELDS = ["body", "title", "state", "number", "url", "author", "head", "base", "draft", "createdAt", "updatedAt"] as const;
|
||||
const PR_READ_JSON_FIELDS = ["body", "title", "state", "number", "url", "author", "head", "base", "draft", "createdAt", "updatedAt", "headRefName", "baseRefName", "mergeable", "mergeStateStatus", "statusCheckRollup"] as const;
|
||||
const PR_READ_JSON_FIELDS = ["body", "title", "state", "stateDetail", "number", "url", "author", "head", "base", "draft", "createdAt", "updatedAt", "closed", "closedAt", "merged", "mergedAt", "mergeCommit", "headRefName", "baseRefName", "mergeable", "mergeStateStatus", "statusCheckRollup"] as const;
|
||||
const ISSUE_LIST_STATES = ["open", "closed", "all"] as const;
|
||||
const BODY_UPDATE_MODES = ["replace", "append"] as const;
|
||||
const BOARD_MUTATION_SECTIONS = ["open", "closed"] as const;
|
||||
@@ -409,6 +409,10 @@ interface GitHubPullRequest {
|
||||
deletions?: number;
|
||||
changed_files?: number;
|
||||
commits?: number;
|
||||
closed_at?: string | null;
|
||||
merged?: boolean | null;
|
||||
merged_at?: string | null;
|
||||
merge_commit_sha?: string | null;
|
||||
mergeable?: string | null;
|
||||
merge_state_status?: string | null;
|
||||
created_at?: string;
|
||||
@@ -742,15 +746,18 @@ function parseOwnerRepoNumberShorthand(raw: string | undefined): GitHubShorthand
|
||||
}
|
||||
|
||||
function readViewSupportedCommands(kind: "issue" | "pr", repo: string, number: number): string[] {
|
||||
const jsonFields = kind === "issue"
|
||||
? "body,title,state,comments"
|
||||
: "body,title,state,head,base,draft,headRefName,baseRefName,mergeable,mergeStateStatus,statusCheckRollup";
|
||||
return [
|
||||
`bun scripts/cli.ts gh ${kind} read ${number} --repo ${repo} --json ${jsonFields}`,
|
||||
`bun scripts/cli.ts gh ${kind} read ${number} --repo ${repo} --json ${readViewSupportedJsonFields(kind)}`,
|
||||
`bun scripts/cli.ts gh ${kind} view ${repo}#${number} --raw`,
|
||||
];
|
||||
}
|
||||
|
||||
function readViewSupportedJsonFields(kind: "issue" | "pr"): string {
|
||||
return kind === "issue"
|
||||
? "body,title,state,comments"
|
||||
: "body,title,state,stateDetail,closed,closedAt,merged,mergedAt,mergeCommit,head,base,draft,headRefName,baseRefName,mergeable,mergeStateStatus,statusCheckRollup";
|
||||
}
|
||||
|
||||
function resolveReadViewNumberReference(kind: "issue" | "pr", sub: "read" | "view", raw: string | undefined, options: GitHubOptions, args: string[]): GitHubResolvedNumberReference | GitHubCommandResult {
|
||||
const command = `${kind} ${sub}`;
|
||||
const shorthand = parseOwnerRepoNumberShorthand(raw);
|
||||
@@ -772,7 +779,7 @@ function resolveReadViewNumberReference(kind: "issue" | "pr", sub: "read" | "vie
|
||||
return {
|
||||
...parsed,
|
||||
supportedCommands: [
|
||||
`bun scripts/cli.ts gh ${kind} read <number> --repo owner/name --json ${kind === "issue" ? "body,title,state,comments" : "body,title,state,head,base"}`,
|
||||
`bun scripts/cli.ts gh ${kind} read <number> --repo owner/name --json ${readViewSupportedJsonFields(kind)}`,
|
||||
`bun scripts/cli.ts gh ${kind} read owner/name#<number> --raw`,
|
||||
],
|
||||
};
|
||||
@@ -815,7 +822,7 @@ function unknownGhOptionDetails(args: string[], option: string): Record<string,
|
||||
details.supportedCommands = number > 0
|
||||
? readViewSupportedCommands(top, repo, number)
|
||||
: [
|
||||
`bun scripts/cli.ts gh ${top} read <number> --repo owner/name --json ${top === "issue" ? "body,title,state,comments" : "body,title,state,head,base"}`,
|
||||
`bun scripts/cli.ts gh ${top} read <number> --repo owner/name --json ${readViewSupportedJsonFields(top)}`,
|
||||
`bun scripts/cli.ts gh ${top} read owner/name#<number> --raw`,
|
||||
];
|
||||
}
|
||||
@@ -3558,13 +3565,23 @@ function commentSummary(comment: GitHubComment): Record<string, unknown> {
|
||||
};
|
||||
}
|
||||
|
||||
function prStateDetail(pr: GitHubPullRequest): "open" | "closed" | "merged" {
|
||||
if (pr.merged === true || pr.merged_at !== null && pr.merged_at !== undefined) return "merged";
|
||||
return pr.state === "closed" ? "closed" : "open";
|
||||
}
|
||||
|
||||
function prSummary(pr: GitHubPullRequest): Record<string, unknown> {
|
||||
const stateDetail = prStateDetail(pr);
|
||||
const closedAt = pr.closed_at ?? pr.merged_at ?? null;
|
||||
const mergedAt = pr.merged_at ?? null;
|
||||
const mergeCommitSha = pr.merge_commit_sha ?? null;
|
||||
return {
|
||||
id: pr.id,
|
||||
number: pr.number,
|
||||
title: pr.title,
|
||||
body: pr.body ?? "",
|
||||
state: pr.state,
|
||||
stateDetail,
|
||||
draft: pr.draft ?? false,
|
||||
url: pr.html_url,
|
||||
author: pr.user?.login ?? null,
|
||||
@@ -3574,6 +3591,11 @@ function prSummary(pr: GitHubPullRequest): Record<string, unknown> {
|
||||
baseRefName: pr.base?.ref ?? null,
|
||||
createdAt: pr.created_at ?? null,
|
||||
updatedAt: pr.updated_at ?? null,
|
||||
closed: stateDetail !== "open",
|
||||
closedAt,
|
||||
merged: stateDetail === "merged",
|
||||
mergedAt,
|
||||
mergeCommit: stateDetail === "merged" && mergeCommitSha !== null ? { oid: mergeCommitSha } : null,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -5023,7 +5045,7 @@ export function ghHelp(): unknown {
|
||||
"bun scripts/cli.ts gh pr list [--repo owner/name] [--state open|closed|all] [--limit N] [--json number,title,state,url,updatedAt,createdAt,author,head,base,draft]",
|
||||
"bun scripts/cli.ts gh pr files <number> [--repo owner/name] [--limit N]",
|
||||
"bun scripts/cli.ts gh pr diff <number> --stat [--repo owner/name] [--limit N] [compatibility alias for pr files; no raw diff]",
|
||||
"bun scripts/cli.ts gh pr read <number|owner/repo#number> [--repo owner/name] [--json body,title,state,head,base,draft,headRefName,baseRefName,mergeable,mergeStateStatus,statusCheckRollup] [--raw|--full]",
|
||||
"bun scripts/cli.ts gh pr read <number|owner/repo#number> [--repo owner/name] [--json body,title,state,stateDetail,closed,closedAt,merged,mergedAt,mergeCommit,head,base,draft,headRefName,baseRefName,mergeable,mergeStateStatus,statusCheckRollup] [--raw|--full]",
|
||||
"bun scripts/cli.ts gh pr view <number|owner/repo#number> [--repo owner/name] [--raw|--full] [compatibility alias for pr read]",
|
||||
"bun scripts/cli.ts gh pr create --title <title> --body-file <file>|--body <text> --base <branch> --head <branch> [--repo owner/name] [--draft] [--dry-run]",
|
||||
"bun scripts/cli.ts gh pr edit <number> [--title title] [--body-file <file>|--body-file -|--body <text>] [--repo owner/name] [--dry-run]",
|
||||
@@ -5059,9 +5081,9 @@ export function ghHelp(): unknown {
|
||||
"Commander brief ClaudeQQ defaults to private target 645275593 through backend-core /api/microservices/claudeqq/proxy; UNIDESK_COMMANDER_BRIEF_CLAUDEQQ_* env vars can override target, base URL, timeout, and enabled state.",
|
||||
"comment delete is supported because GitHub supports deleting issue comments; issue/pr hard delete is unsupported and close is the lifecycle alternative.",
|
||||
"PR files is the canonical compact changed-file/stat summary. It uses GitHub REST, returns bounded file rows, additions/deletions/changes when available, truncation metadata, and a next command for full details. Raw diff patches are not emitted by default; gh pr diff <number> --stat is a compatibility alias for the same JSON summary.",
|
||||
"PR read is the canonical read path; view remains a compatibility alias. PR read/view accept owner/repo#number shorthand and derive --repo unless an explicit conflicting --repo is supplied, which fails structurally with suggested commands. PR read/view supports closeout fields headRefName, baseRefName, mergeable, mergeStateStatus, and statusCheckRollup; mergeability and status rollup are fetched through GitHub GraphQL only when requested or when --raw/--full requests full disclosure.",
|
||||
"PR edit/update PATCHes /repos/{owner}/{repo}/pulls/{number} through REST only, never GitHub Projects Classic GraphQL/projectCards, and returns low-noise JSON with repo, PR number, changedFields, url, and body size/SHA metadata instead of echoing the full body.",
|
||||
"PR create/update/comment are safe-write operations with dry-run planning; merge is intentionally unsupported in this phase.",
|
||||
"PR read is the canonical read path; view remains a compatibility alias. PR read/view accept owner/repo#number shorthand and derive --repo unless an explicit conflicting --repo is supplied, which fails structurally with suggested commands. PR read/view supports REST closeout fields stateDetail, closed, closedAt, merged, mergedAt, mergeCommit, headRefName, and baseRefName; mergeable, mergeStateStatus, and statusCheckRollup are fetched through GitHub GraphQL only when requested or when --raw/--full requests full disclosure.",
|
||||
"PR create/edit/update/comment are safe-write operations with dry-run planning; merge is intentionally unsupported in this phase.",
|
||||
],
|
||||
};
|
||||
}
|
||||
@@ -5102,7 +5124,7 @@ export async function runGhCommand(args: string[]): Promise<GitHubCommandResult
|
||||
"bun scripts/cli.ts gh issue read owner/name#<number> --raw",
|
||||
"bun scripts/cli.ts gh issue read <number> --repo owner/name --json body,title,state,comments",
|
||||
"bun scripts/cli.ts gh pr read owner/name#<number> --raw",
|
||||
"bun scripts/cli.ts gh pr read <number> --repo owner/name --json body,title,state,head,base",
|
||||
`bun scripts/cli.ts gh pr read <number> --repo owner/name --json ${readViewSupportedJsonFields("pr")}`,
|
||||
],
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user