Unify pull request draft title resolution (#5943)
Extract title resolution into a dedicated helper to ensure both inline and dialog pull request creation flows consistently fall back to a normalized and humanized branch slug when no eligibility title is available. - Normalize remote refs before humanizing branch slugs - Pre-populate dialog titles when eligibility title is missing - Update E2E tests to expect pre-populated draft titles
This commit is contained in:
parent
26493072c1
commit
308da355bc
|
|
@ -168,6 +168,7 @@ import {
|
|||
import { getRuntimeRepoBaseRefDefault } from '@/runtime/runtime-repo-client'
|
||||
|
||||
import { stripBaseRef, useCreatePullRequestDialogFields } from './useCreatePullRequestDialogFields'
|
||||
import { resolveCreateReviewDraftTitle } from './create-review-draft-title'
|
||||
import { GitHistoryPanel, type GitHistoryPanelState } from './GitHistoryPanel'
|
||||
import { useGitHistoryCommitActions } from './useGitHistoryCommitActions'
|
||||
import { normalizeHostedReviewHeadRef } from '../../../../shared/hosted-review-refs'
|
||||
|
|
@ -189,7 +190,6 @@ import type {
|
|||
HostedReviewProvider
|
||||
} from '../../../../shared/hosted-review'
|
||||
import { resolveHostedReviewCreationProvider } from '../../../../shared/hosted-review-creation-providers'
|
||||
import { humanizeBranchSlug } from '../../../../shared/branch-name-from-work'
|
||||
import { STATUS_COLORS, STATUS_LABELS } from './status-display'
|
||||
import { isCustomAgentId } from '../../../../shared/commit-message-agent-spec'
|
||||
import {
|
||||
|
|
@ -3117,13 +3117,12 @@ function SourceControlInner(): React.JSX.Element {
|
|||
return false
|
||||
}
|
||||
|
||||
const fallbackTitle =
|
||||
eligibility.title?.trim() ||
|
||||
humanizeBranchSlug(stripBaseRef(token.branch).split('/').pop()?.replace(/_/g, '-') ?? '') ||
|
||||
stripBaseRef(token.branch)
|
||||
let fields = {
|
||||
base,
|
||||
title: fallbackTitle,
|
||||
title: resolveCreateReviewDraftTitle({
|
||||
branch: token.branch,
|
||||
eligibilityTitle: eligibility.title
|
||||
}),
|
||||
body: eligibility.body ?? prBody,
|
||||
draft: resolvedPrCreationDefaults.draft
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,39 @@
|
|||
import { describe, expect, it } from 'vitest'
|
||||
import { resolveCreateReviewDraftTitle } from './create-review-draft-title'
|
||||
|
||||
describe('resolveCreateReviewDraftTitle', () => {
|
||||
it('uses the hosted eligibility title when one is available', () => {
|
||||
expect(
|
||||
resolveCreateReviewDraftTitle({
|
||||
branch: 'feature/improve-diff-view',
|
||||
eligibilityTitle: ' Improve diff view '
|
||||
})
|
||||
).toBe('Improve diff view')
|
||||
})
|
||||
|
||||
it('falls back when the hosted eligibility title is blank', () => {
|
||||
expect(
|
||||
resolveCreateReviewDraftTitle({
|
||||
branch: 'feature/restore-create-review',
|
||||
eligibilityTitle: ' '
|
||||
})
|
||||
).toBe('Restore create review')
|
||||
})
|
||||
|
||||
it('falls back to a readable title from the branch leaf', () => {
|
||||
expect(
|
||||
resolveCreateReviewDraftTitle({
|
||||
branch: 'refs/heads/feature/improve-diff-view-per-file',
|
||||
eligibilityTitle: null
|
||||
})
|
||||
).toBe('Improve diff view per file')
|
||||
})
|
||||
|
||||
it('normalizes remote refs before deriving the branch leaf', () => {
|
||||
expect(
|
||||
resolveCreateReviewDraftTitle({
|
||||
branch: 'refs/remotes/origin/feature/improve-diff-view-per-file'
|
||||
})
|
||||
).toBe('Improve diff view per file')
|
||||
})
|
||||
})
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
import { humanizeBranchSlug } from '../../../../shared/branch-name-from-work'
|
||||
import { normalizeHostedReviewHeadRef } from '../../../../shared/hosted-review-refs'
|
||||
|
||||
export function resolveCreateReviewDraftTitle({
|
||||
branch,
|
||||
eligibilityTitle
|
||||
}: {
|
||||
branch: string
|
||||
eligibilityTitle?: string | null
|
||||
}): string {
|
||||
const title = eligibilityTitle?.trim()
|
||||
if (title) {
|
||||
return title
|
||||
}
|
||||
const normalizedBranch = normalizeHostedReviewHeadRef(branch)
|
||||
const branchLeaf = normalizedBranch.split('/').pop()?.replace(/_/g, '-') ?? ''
|
||||
return humanizeBranchSlug(branchLeaf) || normalizedBranch
|
||||
}
|
||||
|
|
@ -26,6 +26,7 @@ import type {
|
|||
PullRequestFieldName,
|
||||
PullRequestFieldRevisions
|
||||
} from '@/store/slices/pull-request-generation'
|
||||
import { resolveCreateReviewDraftTitle } from './create-review-draft-title'
|
||||
|
||||
type PullRequestDraftFields = {
|
||||
base: string
|
||||
|
|
@ -293,7 +294,7 @@ export function useCreatePullRequestDialogFields({
|
|||
baseEditedByUserRef.current = false
|
||||
syncedDefaultBaseRef.current = resolvedDefaultBaseRef || null
|
||||
setBase(resolvedDefaultBaseRef)
|
||||
setTitle(eligibility.title ?? '')
|
||||
setTitle(resolveCreateReviewDraftTitle({ branch, eligibilityTitle: eligibility.title }))
|
||||
setBody(eligibility.body ?? '')
|
||||
setDraft(resolvedPrDefaults.draft)
|
||||
setBaseQuery('')
|
||||
|
|
|
|||
|
|
@ -213,13 +213,12 @@ test.describe('Source Control create pull request', () => {
|
|||
})
|
||||
const createButton = getCreatePRComposerSubmitButton(orcaPage)
|
||||
await expect(createButton).toBeVisible({ timeout: 10_000 })
|
||||
await expect(createButton).toBeDisabled()
|
||||
await expect(titleInput).toHaveValue('')
|
||||
await expect(createButton).toBeEnabled()
|
||||
await expect(titleInput).toHaveValue('E2e secondary')
|
||||
await expect(orcaPage.getByRole('textbox', { name: 'Pull request base branch' })).toHaveValue(
|
||||
'main'
|
||||
)
|
||||
await expect(descriptionInput).toHaveValue('')
|
||||
await titleInput.fill('Create PR from E2E')
|
||||
await descriptionInput.fill('- Initial commit for E2E')
|
||||
await expect(createButton).toBeEnabled()
|
||||
await createButton.click()
|
||||
|
|
@ -244,7 +243,7 @@ test.describe('Source Control create pull request', () => {
|
|||
provider: 'github',
|
||||
base: 'main',
|
||||
head: branch,
|
||||
title: 'Create PR from E2E',
|
||||
title: 'E2e secondary',
|
||||
body: '- Initial commit for E2E',
|
||||
draft: false
|
||||
})
|
||||
|
|
|
|||
Loading…
Reference in New Issue