refactor(mobile): use shared source-control decisions (#13453)

This commit is contained in:
Neil
2026-08-10 20:41:31 -07:00
committed by GitHub
parent e671c64dea
commit a321ac3c8f
6 changed files with 56 additions and 406 deletions
@@ -60,6 +60,21 @@ export type SourceControlPrimaryActionDecision = {
requiresForceWithLease?: boolean
}
export type SourceControlCommitAreaPrimaryActionDecision = Omit<
SourceControlPrimaryActionDecision,
'kind' | 'labelIntent' | 'titleIntent'
> & {
kind: Exclude<SourceControlPrimaryActionKind, 'create_pr_intent' | 'create_pr'>
labelIntent: Exclude<
SourceControlPrimaryActionDecision['labelIntent'],
'create_pr_intent' | 'create_pr'
>
titleIntent: Exclude<
SourceControlPrimaryActionTitleIntent,
'prepare_review' | 'create_review' | 'checking_review_creation'
>
}
export type SourceControlPrimaryActionDecisionInputs = {
stagedCount: number
hasUnstagedChanges: boolean
@@ -159,25 +159,30 @@ describe('source-control primary action decision', () => {
expect(resolveSourceControlCommitAreaPrimaryActionDecision(input).kind).toBe('commit')
})
it('keeps in-flight review intents out of commit-area decisions', () => {
const input = inputs({ isPrIntentInFlight: true })
expect(resolveSourceControlPrimaryActionDecision(input).kind).toBe('create_pr_intent')
expect(resolveSourceControlCommitAreaPrimaryActionDecision(input).kind).toBe('commit')
})
it('returns disabled create review while hosted-review creation eligibility is loading', () => {
const result = resolveSourceControlPrimaryActionDecision(
inputs({
upstreamStatus: { hasUpstream: true, ahead: 0, behind: 0 },
hostedReviewCreation: {
provider: 'gitlab',
review: null,
canCreate: false,
blockedReason: null,
nextAction: null,
reviewLookupOutcome: 'not_found'
},
isHostedReviewCreationLoading: true
})
)
expect(result).toMatchObject({
const input = inputs({
upstreamStatus: { hasUpstream: true, ahead: 0, behind: 0 },
hostedReviewCreation: {
provider: 'gitlab',
review: null,
canCreate: false,
blockedReason: null,
nextAction: null,
reviewLookupOutcome: 'not_found'
},
isHostedReviewCreationLoading: true
})
expect(resolveSourceControlPrimaryActionDecision(input)).toMatchObject({
kind: 'create_pr',
titleIntent: 'checking_review_creation',
disabled: true
})
expect(resolveSourceControlCommitAreaPrimaryActionDecision(input).kind).toBe('commit')
})
})
@@ -3,6 +3,7 @@ import { supportsHostedReviewCreation } from './hosted-review-creation-providers
import { resolveCreateReviewIntentEligibility } from './source-control-create-review-intent'
import { resolveSourceControlPrimaryActionDuringRemoteOp } from './source-control-primary-action-in-flight'
import type {
SourceControlCommitAreaPrimaryActionDecision,
SourceControlPrimaryActionDecision,
SourceControlPrimaryActionDecisionInputs
} from './source-control-primary-action-decision-types'
@@ -11,6 +12,7 @@ import { resolveUnpublishedSourceControlPrimaryAction } from './source-control-p
export type {
SourceControlPrimaryActionKind,
SourceControlRemoteOpKind,
SourceControlCommitAreaPrimaryActionDecision,
SourceControlPrimaryActionDecision,
SourceControlPrimaryActionDecisionInputs
} from './source-control-primary-action-decision-types'
@@ -221,14 +223,14 @@ function shouldOfferCreateReviewLoadingAction(
export function resolveSourceControlCommitAreaPrimaryActionDecision(
inputs: SourceControlPrimaryActionDecisionInputs
): SourceControlPrimaryActionDecision {
): SourceControlCommitAreaPrimaryActionDecision {
// Why: review creation is additive chrome. Commit/mobile bottom areas keep
// the local/remote action they would have without review eligibility.
return resolveSourceControlPrimaryActionDecision({
...inputs,
hostedReviewCreation: null,
isPrIntentInFlight: false
})
}) as SourceControlCommitAreaPrimaryActionDecision
}
function resolveCreatePrIntentDecision(