Files
orca/mobile/src/source-control/mobile-pr-create.ts
T
Jinjing d67ede1594 Implement confirm-only PR panel composer with classified error blocking (#9428)
* Clarify PR panel guidance: classify errors and confirm-only composer

Replace the ambiguous GitHub hosted-review boolean with a four-state evidence
model (found/positive_unresolved/not_found/unknown) so "No PR found" never
appears without an accepted lookup result. Classify GitHub refresh failures
into types (rate_limited, auth, network, permission, repo_unavailable,
gh_unavailable, unknown) for stable, honest copy. Confirmed-only composer:
preserve drafts across transient failures; hide Create during hard errors and
positive-unresolved evidence. Hard errors clear only when an eligibility
request starts after the error and returns an accepted outcome. Propagate
error types and unified retry schedule through the store. Sync mobile parity
with shouldOpenChecksPanelCreateComposer gating. Localize all new copy.

* Clarify PR panel guidance: classify errors and confirm-only composer

Add reviewLookupOutcome to hosted-review eligibility and thread it through
the panel so it never claims "No PR found" without accepted evidence. A
failed lookup is unavailable, not a settled no-PR. Fail closed on positive
unresolved evidence, hard refresh errors, and unavailable lookups. Add
structured GitHub refresh-error classification with Retry-After parsing.
Implement confirmed-only composer gating based on fresh, matching-context
eligibility with hard-error clearing. Mobile gates on reviewLookupOutcome
to prevent false Create claims. Surface throwOnFailure variants for each
provider so transport failures cross the RPC boundary instead of collapsing
to null. (Design success criteria 1–4; invariant 8.)

* Add exec-error helpers for subprocess error classification

Extracts stderr/stdout parsing and Retry-After detection into a
lightweight module that can be imported without pulling in the heavier
runner machinery. Supports PR-refresh error classification and proper
rate-limit handling for gh commands.

* test(mobile): include reviewLookupOutcome in create eligibility fixtures

Create / Push & Create now fails closed unless the lookup is not_found.
Update mobile test fixtures so accepted-no-PR cases can still proceed.

* Add OrThrow mock variants to forge-provider test mocks

forge-provider resolves branch reviews via the OrThrow variant so
lookup failures surface as unavailable instead of "no PR found".
2026-07-19 16:32:36 -07:00

89 lines
3.8 KiB
TypeScript

import { hostedReviewCopy } from './hosted-review-copy'
import {
buildMobileHostedReviewCreateParams,
createMobileHostedReview,
fetchMobileHostedReviewEligibility,
mobileRepoSelectorFromWorktreeId,
resolveMobileHostedReviewPrefill,
shouldPushBeforeMobileHostedReviewCreate,
type MobileHostedReviewCreateInput,
type MobileHostedReviewCreateOutcome,
type MobileHostedReviewEligibilityInput,
type MobileHostedReviewPrefill
} from './mobile-hosted-review-service'
export type MobilePrEligibilityInput = MobileHostedReviewEligibilityInput
export type MobilePrPrefill = MobileHostedReviewPrefill
export type MobilePrCreateInput = MobileHostedReviewCreateInput
export type MobilePrCreateOutcome = MobileHostedReviewCreateOutcome
export {
buildMobileHostedReviewCreateParams as buildMobilePrCreateParams,
createMobileHostedReview as createMobilePr,
fetchMobileHostedReviewEligibility as fetchMobilePrEligibility,
mobileRepoSelectorFromWorktreeId,
resolveMobileHostedReviewPrefill as resolveMobilePrPrefill,
shouldPushBeforeMobileHostedReviewCreate as shouldPushBeforeMobilePrCreate
}
export function getMobilePrCreateSuccessWarning(
outcome: Extract<MobilePrCreateOutcome, { ok: true }>,
provider: MobilePrPrefill['provider']
): string | undefined {
const copy = hostedReviewCopy(provider)
if (outcome.existing) {
return outcome.number
? `${copy.titleLabel} #${outcome.number} is already open.`
: `${copy.titleLabel} is already open.`
}
if (outcome.linkError) {
return `${copy.titleLabel} created, but Orca could not refresh it yet.`
}
return undefined
}
export function getMobilePrCreateBlockMessage(prefill: MobilePrPrefill): string | null {
const copy = hostedReviewCopy(prefill.provider)
if (prefill.canCreate !== false || shouldPushBeforeMobileHostedReviewCreate(prefill)) {
// Fail closed: only an accepted no-review lookup (`not_found`) may open
// Create / Push & Create. `unavailable`, `found`, or a missing outcome (an
// older host that predates the field) all leave review existence unproven —
// mobile has no refresh/review-lookup signal of its own, so it must not
// offer create, or the needs_push Push & Create path would slip through.
if (prefill.reviewLookupOutcome !== 'not_found') {
return `Orca could not confirm whether this branch already has a ${copy.reviewLabel}. Try again in a moment.`
}
return null
}
switch (prefill.blockedReason) {
case 'dirty':
return `Commit changes before creating a ${copy.reviewLabel}.`
case 'detached_head':
return `Check out a branch before creating a ${copy.reviewLabel}.`
case 'default_branch':
return `Switch to a feature branch before creating a ${copy.reviewLabel}.`
case 'no_upstream':
return `Publish commits before creating a ${copy.reviewLabel}.`
case 'needs_sync':
return `Sync this branch before creating a ${copy.reviewLabel}.`
case 'auth_required':
return `Authenticate before creating a ${copy.reviewLabel}.`
case 'unsupported_provider':
return `Creating ${copy.reviewLabel}s is not supported for this repo.`
case 'existing_review':
return `A ${copy.reviewLabel} already exists for this branch.`
case 'fork_head_unsupported':
return `Creating a ${copy.reviewLabel} from this fork is not supported.`
case 'base_not_on_remote':
return `Push the base branch before creating a ${copy.reviewLabel}.`
case 'needs_push':
case null:
case undefined:
return `This branch is not ready for a ${copy.reviewLabel} yet.`
default:
// Why: desktop can add blocked reasons before a long-lived mobile branch
// catches up; remain safely blocked while preserving merge-ref typechecks.
return `This branch is not ready for a ${copy.reviewLabel} yet.`
}
}