fix: use base ref details for review creation (#4169)

This commit is contained in:
Neil
2026-05-31 06:47:12 -07:00
committed by GitHub
parent 3c23cd57a3
commit a5d7896f1b
2 changed files with 56 additions and 3 deletions
@@ -0,0 +1,34 @@
import { describe, expect, it } from 'vitest'
import { normalizeCreateReviewBaseSearchResults } from './useCreatePullRequestDialogFields'
describe('normalizeCreateReviewBaseSearchResults', () => {
it('uses detailed local branch names for base refs from arbitrary remotes', () => {
expect(
normalizeCreateReviewBaseSearchResults([
{
refName: 'mycorp-fork/main',
localBranchName: 'main'
}
])
).toEqual(['main'])
})
it('dedupes equivalent base branches found on multiple remotes', () => {
expect(
normalizeCreateReviewBaseSearchResults([
{
refName: 'origin/main',
localBranchName: 'main'
},
{
refName: 'upstream/main',
localBranchName: 'main'
},
{
refName: 'mycorp-fork/release/1.0',
localBranchName: 'release/1.0'
}
])
).toEqual(['main', 'release/1.0'])
})
})
@@ -10,7 +10,7 @@ import {
} from '@/runtime/runtime-git-client'
import {
getRuntimeRepoBaseRefDefault,
searchRuntimeRepoBaseRefs
searchRuntimeRepoBaseRefDetails
} from '@/runtime/runtime-repo-client'
import {
isCustomAgentId,
@@ -18,6 +18,7 @@ import {
} from '../../../../shared/commit-message-agent-spec'
import type { HostedReviewCreationEligibility } from '../../../../shared/hosted-review'
import { normalizeHostedReviewBaseRef } from '../../../../shared/hosted-review-refs'
import type { BaseRefSearchResult } from '../../../../shared/types'
import {
DEFAULT_SOURCE_CONTROL_AI_PR_CREATION_DEFAULTS,
normalizeSourceControlAiSettings
@@ -71,6 +72,24 @@ export function stripBaseRef(ref: string): string {
return normalizeHostedReviewBaseRef(ref)
}
export function normalizeCreateReviewBaseSearchResults(
results: readonly BaseRefSearchResult[]
): string[] {
const seen = new Set<string>()
const branches: string[] = []
for (const result of results) {
// Why: hosted review APIs take branch names, while base search displays
// remote-qualified refs. Detailed search already resolves slashy remotes.
const branch = stripBaseRef((result.localBranchName || result.refName).trim())
if (!branch || seen.has(branch)) {
continue
}
seen.add(branch)
branches.push(branch)
}
return branches
}
export function useCreatePullRequestDialogFields({
open,
repoId,
@@ -266,10 +285,10 @@ export function useCreatePullRequestDialogFields({
}
let stale = false
const timer = window.setTimeout(() => {
void searchRuntimeRepoBaseRefs(settings, repoId, baseQuery.trim(), 20)
void searchRuntimeRepoBaseRefDetails(settings, repoId, baseQuery.trim(), 20)
.then((results) => {
if (!stale) {
setBaseResults(results.map(stripBaseRef))
setBaseResults(normalizeCreateReviewBaseSearchResults(results))
setBaseSearchError(null)
}
})