Use work item titles for create-from workspace names
This commit is contained in:
@@ -2,6 +2,7 @@ import { describe, expect, it } from 'vitest'
|
||||
import {
|
||||
getLinearIssueWorkspaceName,
|
||||
getLinkedWorkItemSuggestedName,
|
||||
getLinkedWorkItemWorkspaceName,
|
||||
getWorkspaceIntentName,
|
||||
resolveWorkspaceCreateName,
|
||||
slugifyForWorkspaceName
|
||||
@@ -35,6 +36,36 @@ describe('getLinkedWorkItemSuggestedName', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('getLinkedWorkItemWorkspaceName', () => {
|
||||
it('uses the resolved GitHub title instead of the source URL or provider number', () => {
|
||||
expect(
|
||||
getLinkedWorkItemWorkspaceName({
|
||||
type: 'pr',
|
||||
number: 2049,
|
||||
title: 'Fix pasted URL workspace names'
|
||||
})
|
||||
).toEqual({
|
||||
displayName: 'Fix pasted URL workspace names',
|
||||
seedName: 'fix-pasted-url-workspace-names'
|
||||
})
|
||||
})
|
||||
|
||||
it('keeps external provider identifiers without duplicating title prefixes', () => {
|
||||
expect(
|
||||
getLinkedWorkItemWorkspaceName({
|
||||
type: 'issue',
|
||||
provider: 'jira',
|
||||
number: 0,
|
||||
title: 'PROJ-7 Fix flaky import',
|
||||
jiraIdentifier: 'PROJ-7'
|
||||
})
|
||||
).toEqual({
|
||||
displayName: 'PROJ-7 Fix flaky import',
|
||||
seedName: 'proj-7-fix-flaky-import'
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('getWorkspaceIntentName', () => {
|
||||
it('uses explicit user intent for linked issues without copying long titles', () => {
|
||||
expect(
|
||||
|
||||
@@ -33,14 +33,7 @@ export function slugifyForWorkspaceName(input: string): string {
|
||||
}
|
||||
|
||||
export function getLinkedWorkItemSuggestedName(item: { title: string }): string {
|
||||
const withoutLeadingNumber = item.title
|
||||
.trim()
|
||||
.replace(/^(?:issue|pr|pull request)\s*#?\d+\s*[:-]\s*/i, '')
|
||||
.replace(/^#\d+\s*[:-]\s*/, '')
|
||||
.replace(/\(#\d+\)/gi, '')
|
||||
.replace(/\b#\d+\b/g, '')
|
||||
.trim()
|
||||
const seed = withoutLeadingNumber || item.title.trim()
|
||||
const seed = getLinkedWorkItemTitleSubject(item) || item.title.trim()
|
||||
return slugifyForWorkspaceName(seed)
|
||||
}
|
||||
|
||||
@@ -58,6 +51,16 @@ export type WorkspaceIntentName = {
|
||||
seedName: string
|
||||
}
|
||||
|
||||
function getLinkedWorkItemTitleSubject(item: { title: string }): string {
|
||||
return item.title
|
||||
.trim()
|
||||
.replace(/^(?:issue|pr|pull request|mr|merge request)\s*[#!]?\d+\s*[:-]\s*/i, '')
|
||||
.replace(/^#\d+\s*[:-]\s*/, '')
|
||||
.replace(/\([#!]?\d+\)/g, '')
|
||||
.replace(/\b#\d+\b/g, '')
|
||||
.trim()
|
||||
}
|
||||
|
||||
// Why: generated workspace seeds are hyphenated; `issue-123-fix-title`
|
||||
// must not be reinterpreted as the user explicitly asking to fix a new issue.
|
||||
const ACTION_LABELS: [RegExp, string][] = [
|
||||
@@ -169,6 +172,24 @@ function workItemIdentity(item: WorkspaceIntentWorkItem): string {
|
||||
return `Issue ${item.number}`
|
||||
}
|
||||
|
||||
export function getLinkedWorkItemWorkspaceName(
|
||||
item: WorkspaceIntentWorkItem
|
||||
): WorkspaceIntentName | null {
|
||||
const identifier = item.linearIdentifier ?? item.jiraIdentifier
|
||||
let subject = getLinkedWorkItemTitleSubject(item) || item.title.trim()
|
||||
if (identifier) {
|
||||
subject = subject
|
||||
.replace(new RegExp(`^${escapeRegExp(identifier)}\\s*[:-]?\\s*`, 'i'), '')
|
||||
.trim()
|
||||
}
|
||||
const displayName = [identifier, subject].filter(Boolean).join(' ') || workItemIdentity(item)
|
||||
const seedName = slugifyForWorkspaceName(displayName)
|
||||
if (!seedName) {
|
||||
return null
|
||||
}
|
||||
return { displayName, seedName }
|
||||
}
|
||||
|
||||
function defaultActionForWorkItem(item: WorkspaceIntentWorkItem): string | null {
|
||||
return item.type === 'pr' || item.type === 'mr' ? 'Review' : null
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user