mirror of
https://github.com/stablyai/orca.git
synced 2026-10-19 08:03:13 +00:00
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Co-authored-by: Orca <help@stably.ai> Co-authored-by: gsxdsm <gsxdsm@users.noreply.github.com>
56 lines
1.8 KiB
TypeScript
56 lines
1.8 KiB
TypeScript
// Ref normalizers ported from src/shared/hosted-review-refs.ts (value-imported, not
|
|
// referenced across the package boundary — Metro's resolver is rooted at mobile/ and
|
|
// can't bundle a runtime import from repo-root/src, unlike erased `import type`s).
|
|
// Keep in sync with the shared versions so mobile and desktop compare refs identically.
|
|
function normalizeHeadRef(ref: string): string {
|
|
return ref
|
|
.trim()
|
|
.replace(/^refs\/heads\//, '')
|
|
.replace(/^refs\/remotes\/[^/]+\//, '')
|
|
}
|
|
|
|
function normalizeBaseRef(ref: string): string {
|
|
return normalizeHeadRef(ref).replace(/^(origin|upstream)\//, '')
|
|
}
|
|
|
|
// Submit-gating for the create-PR composer, matching desktop CreatePullRequestDialog:
|
|
// the base ref must be non-empty and must differ from the head branch after ref
|
|
// normalization (strip refs/heads, remote prefixes, origin/upstream), case-insensitive.
|
|
export function isBaseHeadDistinct(base: string, head: string): boolean {
|
|
const b = normalizeBaseRef(base).toLowerCase()
|
|
const h = normalizeHeadRef(head).toLowerCase()
|
|
return b.length > 0 && b !== h
|
|
}
|
|
|
|
export function canSubmitPrCompose(title: string, base: string, head: string): boolean {
|
|
return title.trim().length > 0 && isBaseHeadDistinct(base, head)
|
|
}
|
|
|
|
export function getPrComposeDisabledReason({
|
|
title,
|
|
base,
|
|
head,
|
|
generating,
|
|
reviewLabel
|
|
}: {
|
|
title: string
|
|
base: string
|
|
head: string
|
|
generating: boolean
|
|
reviewLabel: string
|
|
}): string | null {
|
|
if (generating) {
|
|
return 'Wait for generation to finish.'
|
|
}
|
|
if (title.trim().length === 0) {
|
|
return `Enter a ${reviewLabel} title.`
|
|
}
|
|
if (base.trim().length === 0) {
|
|
return 'Choose a base branch.'
|
|
}
|
|
if (!isBaseHeadDistinct(base, head)) {
|
|
return 'Base branch must differ from the head branch.'
|
|
}
|
|
return null
|
|
}
|