mirror of
https://github.com/stablyai/orca.git
synced 2026-10-04 00:02:21 +00:00
read.bootstrap() folded status.get and the settings fan-out behind one await, so the supported commit ran only after all five requests succeeded. A post-connect timeout on any of the four left tasksSupportState at 'unknown', which the list surface renders as a bare spinner, and the effect deps do not change on that failure so it never retried. The probe is now read.tasksSupported() and the fan-out is read.bootstrap(), with the caller committing supported and clearing the error between them, as it did before the seam existed. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
359 lines
12 KiB
TypeScript
359 lines
12 KiB
TypeScript
import type { GitHubPRMergeMethod } from '../../../src/shared/github/pull-request-types'
|
|
import type { RpcRequestSender } from '../transport/rpc-client'
|
|
import { buildGithubPrParams, githubPrRepoSlugParam, type GitHubPrRepoSlug } from './github-pr-rpc'
|
|
|
|
// Mutation wrappers for the github.* PR surface, split out so github-pr-rpc.ts
|
|
// stays under the max-lines budget. They mirror the read wrappers' shape but
|
|
// return a host-status outcome (the host mutations all return
|
|
// `{ ok: true } | { ok: false; error: string }`).
|
|
|
|
// `comment` is the server-created entry when the host publishes one; callers that echo the
|
|
// comment optimistically need its real id, not a locally minted stub.
|
|
export type GitHubPrMutationOutcome = { ok: true; comment?: unknown } | { ok: false; error: string }
|
|
|
|
// Sends a request whose host result is a bare boolean (not the `{ ok }` envelope),
|
|
// normalizing a transport throw into a failure so the raw-boolean callers below
|
|
// never see an unhandled rejection.
|
|
type RawResult = { ok: true; result: unknown } | { ok: false; error: string }
|
|
|
|
async function sendRaw(
|
|
client: RpcRequestSender,
|
|
method: string,
|
|
params: Record<string, unknown>,
|
|
options?: { timeoutMs?: number }
|
|
): Promise<RawResult> {
|
|
try {
|
|
// Keep the two-argument call shape when no timeout is requested.
|
|
const response = options
|
|
? await client.sendRequest(method, params, options)
|
|
: await client.sendRequest(method, params)
|
|
if (!response.ok) {
|
|
return { ok: false, error: response.error?.message || `Request failed: ${method}` }
|
|
}
|
|
return { ok: true, result: response.result }
|
|
} catch (err) {
|
|
return { ok: false, error: err instanceof Error ? err.message : `Request failed: ${method}` }
|
|
}
|
|
}
|
|
|
|
// Host failure `error` is either a bare string (github.* PR mutations) or an
|
|
// object `{ message }` (github.project.* slug mutations). Read whichever is present
|
|
// so the slug edit/delete failures surface a real message, not a generic fallback.
|
|
function extractMutationError(error: unknown, method: string): string {
|
|
if (typeof error === 'string') {
|
|
return error
|
|
}
|
|
if (error && typeof error === 'object' && 'message' in error) {
|
|
const message = (error as { message?: unknown }).message
|
|
if (typeof message === 'string' && message.length > 0) {
|
|
return message
|
|
}
|
|
}
|
|
return `Request failed: ${method}`
|
|
}
|
|
|
|
// The host returns the success/failure shape inside `result`; a transport-level
|
|
// `response.ok === false` (timeout/connection) is also a failure. Both collapse
|
|
// into one outcome the action hook classifies via classifyPrSidebarFailure.
|
|
async function sendGithubPrMutation(
|
|
client: RpcRequestSender,
|
|
method: string,
|
|
params: Record<string, unknown>,
|
|
options?: { timeoutMs?: number }
|
|
): Promise<GitHubPrMutationOutcome> {
|
|
try {
|
|
// Keep the two-argument call shape when no timeout is requested.
|
|
const response = options
|
|
? await client.sendRequest(method, params, options)
|
|
: await client.sendRequest(method, params)
|
|
if (!response.ok) {
|
|
return { ok: false, error: response.error?.message || `Request failed: ${method}` }
|
|
}
|
|
const result = response.result
|
|
if (result && typeof result === 'object' && 'ok' in result) {
|
|
const r = result as { ok: boolean; error?: unknown; comment?: unknown }
|
|
if (r.ok === true) {
|
|
return { ok: true, comment: r.comment }
|
|
}
|
|
return { ok: false, error: extractMutationError(r.error, method) }
|
|
}
|
|
// No structured status (host returned void/undefined) — treat as success.
|
|
return { ok: true }
|
|
} catch (err) {
|
|
// Why: a transport drop must not escape as an unhandled rejection — normalize
|
|
// to the `{ ok:false, error }` outcome the action engine routes on.
|
|
return { ok: false, error: err instanceof Error ? err.message : `Request failed: ${method}` }
|
|
}
|
|
}
|
|
|
|
export async function fetchMergePR(
|
|
client: RpcRequestSender,
|
|
worktreeId: string,
|
|
args: { prNumber: number; method?: GitHubPRMergeMethod; prRepo?: GitHubPrRepoSlug | null },
|
|
options?: { timeoutMs?: number }
|
|
): Promise<GitHubPrMutationOutcome> {
|
|
const params: Record<string, unknown> = { prNumber: args.prNumber }
|
|
if (args.method) {
|
|
params.method = args.method
|
|
}
|
|
return sendGithubPrMutation(
|
|
client,
|
|
'github.mergePR',
|
|
buildGithubPrParams('github.mergePR', worktreeId, params, { prRepo: args.prRepo }),
|
|
options
|
|
)
|
|
}
|
|
|
|
// Edit the hosted-review title. The host returns a bare boolean (true on success),
|
|
// which sendGithubPrMutation reads via its "no structured status" success branch
|
|
// only when not boolean — so handle the boolean explicitly like resolveReviewThread.
|
|
export async function fetchUpdatePRTitle(
|
|
client: RpcRequestSender,
|
|
worktreeId: string,
|
|
args: { prNumber: number; title: string; prRepo?: GitHubPrRepoSlug | null }
|
|
): Promise<GitHubPrMutationOutcome> {
|
|
const params: Record<string, unknown> = { prNumber: args.prNumber, title: args.title }
|
|
const response = await sendRaw(
|
|
client,
|
|
'github.updatePRTitle',
|
|
buildGithubPrParams('github.updatePRTitle', worktreeId, params, { prRepo: args.prRepo })
|
|
)
|
|
if (!response.ok) {
|
|
return { ok: false, error: response.error || 'Request failed: github.updatePRTitle' }
|
|
}
|
|
// Why: the host returns a bare `true` on success; a missing/undefined result is
|
|
// not a confirmed success, so require an explicit `=== true` rather than `!== false`.
|
|
if (response.result !== true) {
|
|
return { ok: false, error: 'Failed to update title.' }
|
|
}
|
|
return { ok: true }
|
|
}
|
|
|
|
export async function fetchSetPRAutoMerge(
|
|
client: RpcRequestSender,
|
|
worktreeId: string,
|
|
args: {
|
|
prNumber: number
|
|
enabled: boolean
|
|
method?: GitHubPRMergeMethod
|
|
prRepo?: GitHubPrRepoSlug | null
|
|
}
|
|
): Promise<GitHubPrMutationOutcome> {
|
|
const params: Record<string, unknown> = { prNumber: args.prNumber, enabled: args.enabled }
|
|
if (args.method) {
|
|
params.method = args.method
|
|
}
|
|
return sendGithubPrMutation(
|
|
client,
|
|
'github.setPRAutoMerge',
|
|
buildGithubPrParams('github.setPRAutoMerge', worktreeId, params, { prRepo: args.prRepo })
|
|
)
|
|
}
|
|
|
|
export async function fetchUpdatePRState(
|
|
client: RpcRequestSender,
|
|
worktreeId: string,
|
|
args: { prNumber: number; state: 'open' | 'closed'; prRepo?: GitHubPrRepoSlug | null }
|
|
): Promise<GitHubPrMutationOutcome> {
|
|
return sendGithubPrMutation(
|
|
client,
|
|
'github.updatePRState',
|
|
buildGithubPrParams(
|
|
'github.updatePRState',
|
|
worktreeId,
|
|
{ prNumber: args.prNumber, updates: { state: args.state } },
|
|
{ prRepo: args.prRepo }
|
|
)
|
|
)
|
|
}
|
|
|
|
export async function fetchRequestPRReviewers(
|
|
client: RpcRequestSender,
|
|
worktreeId: string,
|
|
args: { prNumber: number; reviewers: string[]; prRepo?: GitHubPrRepoSlug | null },
|
|
options?: { timeoutMs?: number }
|
|
): Promise<GitHubPrMutationOutcome> {
|
|
return sendGithubPrMutation(
|
|
client,
|
|
'github.requestPRReviewers',
|
|
buildGithubPrParams(
|
|
'github.requestPRReviewers',
|
|
worktreeId,
|
|
{ prNumber: args.prNumber, reviewers: args.reviewers },
|
|
{ prRepo: args.prRepo }
|
|
),
|
|
options
|
|
)
|
|
}
|
|
|
|
export async function fetchRemovePRReviewers(
|
|
client: RpcRequestSender,
|
|
worktreeId: string,
|
|
args: { prNumber: number; reviewers: string[]; prRepo?: GitHubPrRepoSlug | null }
|
|
): Promise<GitHubPrMutationOutcome> {
|
|
return sendGithubPrMutation(
|
|
client,
|
|
'github.removePRReviewers',
|
|
buildGithubPrParams(
|
|
'github.removePRReviewers',
|
|
worktreeId,
|
|
{ prNumber: args.prNumber, reviewers: args.reviewers },
|
|
{ prRepo: args.prRepo }
|
|
)
|
|
)
|
|
}
|
|
|
|
// Reply within a review thread. Host returns GitHubCommentResult
|
|
// (`{ ok, comment } | { ok:false, error }`), which sendGithubPrMutation reads via
|
|
// its `ok in result` branch. We refetch afterward, so the returned comment is unused.
|
|
export async function fetchAddPRReviewCommentReply(
|
|
client: RpcRequestSender,
|
|
worktreeId: string,
|
|
args: {
|
|
prNumber: number
|
|
commentId: number
|
|
body: string
|
|
threadId?: string
|
|
path?: string
|
|
line?: number
|
|
prRepo?: GitHubPrRepoSlug | null
|
|
},
|
|
options?: { timeoutMs?: number }
|
|
): Promise<GitHubPrMutationOutcome> {
|
|
const params: Record<string, unknown> = {
|
|
prNumber: args.prNumber,
|
|
commentId: args.commentId,
|
|
body: args.body
|
|
}
|
|
if (args.threadId) {
|
|
params.threadId = args.threadId
|
|
}
|
|
if (args.path) {
|
|
params.path = args.path
|
|
}
|
|
if (typeof args.line === 'number') {
|
|
params.line = args.line
|
|
}
|
|
return sendGithubPrMutation(
|
|
client,
|
|
'github.addPRReviewCommentReply',
|
|
buildGithubPrParams('github.addPRReviewCommentReply', worktreeId, params, {
|
|
prRepo: args.prRepo
|
|
}),
|
|
options
|
|
)
|
|
}
|
|
|
|
// Add a root conversation comment to a PR or an issue. Host returns GitHubCommentResult.
|
|
export async function fetchAddIssueComment(
|
|
client: RpcRequestSender,
|
|
worktreeId: string,
|
|
args: {
|
|
prNumber: number
|
|
body: string
|
|
prRepo?: GitHubPrRepoSlug | null
|
|
// Why: the host addresses the comment by this; an issue row sent as 'pr' targets the
|
|
// wrong conversation. PR call sites omit it.
|
|
type?: 'issue' | 'pr'
|
|
},
|
|
options?: { timeoutMs?: number }
|
|
): Promise<GitHubPrMutationOutcome> {
|
|
const params: Record<string, unknown> = {
|
|
number: args.prNumber,
|
|
body: args.body,
|
|
type: args.type ?? 'pr'
|
|
}
|
|
return sendGithubPrMutation(
|
|
client,
|
|
'github.addIssueComment',
|
|
buildGithubPrParams('github.addIssueComment', worktreeId, params, { prRepo: args.prRepo }),
|
|
options
|
|
)
|
|
}
|
|
|
|
// Resolve/unresolve a review thread. `resolve` picks the direction (the host runs
|
|
// the matching GraphQL mutation). Unlike the comment mutations, the host returns a
|
|
// bare boolean, so a falsy result is a failure rather than the "no status" success.
|
|
export async function fetchResolveReviewThread(
|
|
client: RpcRequestSender,
|
|
worktreeId: string,
|
|
args: { threadId: string; resolve: boolean; prRepo?: GitHubPrRepoSlug | null },
|
|
options?: { timeoutMs?: number }
|
|
): Promise<GitHubPrMutationOutcome> {
|
|
const response = await sendRaw(
|
|
client,
|
|
'github.resolveReviewThread',
|
|
buildGithubPrParams(
|
|
'github.resolveReviewThread',
|
|
worktreeId,
|
|
{ threadId: args.threadId, resolve: args.resolve },
|
|
{ prRepo: args.prRepo }
|
|
),
|
|
options
|
|
)
|
|
if (!response.ok) {
|
|
return {
|
|
ok: false,
|
|
error: response.error || 'Request failed: github.resolveReviewThread'
|
|
}
|
|
}
|
|
// Why: the host returns a bare `true` on success; a missing/undefined result is
|
|
// not a confirmed success, so require an explicit `=== true` rather than `!== false`.
|
|
if (response.result !== true) {
|
|
return { ok: false, error: 'Failed to update review thread.' }
|
|
}
|
|
return { ok: true }
|
|
}
|
|
|
|
// Edit a root conversation (issue) comment. The host RPC is slug-addressed
|
|
// (owner/repo/commentId), not worktree-addressed, so the params are passed
|
|
// directly rather than via buildGithubPrParams. Host returns the
|
|
// GitHubProjectMutationResult `{ ok }` envelope sendGithubPrMutation reads.
|
|
export async function fetchUpdateIssueComment(
|
|
client: RpcRequestSender,
|
|
args: { owner: string; repo: string; host?: string; commentId: number; body: string }
|
|
): Promise<GitHubPrMutationOutcome> {
|
|
return sendGithubPrMutation(client, 'github.project.updateIssueCommentBySlug', {
|
|
...githubPrRepoSlugParam(args),
|
|
commentId: args.commentId,
|
|
body: args.body
|
|
})
|
|
}
|
|
|
|
// Delete a root conversation (issue) comment. Slug-addressed like the edit wrapper.
|
|
export async function fetchDeleteIssueComment(
|
|
client: RpcRequestSender,
|
|
args: { owner: string; repo: string; host?: string; commentId: number }
|
|
): Promise<GitHubPrMutationOutcome> {
|
|
return sendGithubPrMutation(client, 'github.project.deleteIssueCommentBySlug', {
|
|
...githubPrRepoSlugParam(args),
|
|
commentId: args.commentId
|
|
})
|
|
}
|
|
|
|
export async function fetchRerunPRChecks(
|
|
client: RpcRequestSender,
|
|
worktreeId: string,
|
|
args: {
|
|
prNumber: number
|
|
headSha?: string | null
|
|
failedOnly?: boolean
|
|
prRepo?: GitHubPrRepoSlug | null
|
|
},
|
|
options?: { timeoutMs?: number }
|
|
): Promise<GitHubPrMutationOutcome> {
|
|
const params: Record<string, unknown> = { prNumber: args.prNumber }
|
|
if (args.failedOnly !== undefined) {
|
|
params.failedOnly = args.failedOnly
|
|
}
|
|
if (args.headSha) {
|
|
params.headSha = args.headSha
|
|
}
|
|
return sendGithubPrMutation(
|
|
client,
|
|
'github.rerunPRChecks',
|
|
buildGithubPrParams('github.rerunPRChecks', worktreeId, params, { prRepo: args.prRepo }),
|
|
options
|
|
)
|
|
}
|