37 lines
1.1 KiB
TypeScript
37 lines
1.1 KiB
TypeScript
export function slugifyForWorkspaceName(input: string): string {
|
|
return (
|
|
input
|
|
.trim()
|
|
.toLowerCase()
|
|
.replace(/[\\/]+/g, '-')
|
|
.replace(/\s+/g, '-')
|
|
.replace(/[^a-z0-9._-]+/g, '-')
|
|
.replace(/-+/g, '-')
|
|
// Why: git check-ref-format rejects any ref containing `..`, so previews
|
|
// must match the main-process sanitizer before workspace creation.
|
|
.replace(/\.{2,}/g, '.')
|
|
.replace(/^[.-]+|[.-]+$/g, '')
|
|
.slice(0, 48)
|
|
.replace(/[-._]+$/g, '')
|
|
)
|
|
}
|
|
|
|
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()
|
|
return slugifyForWorkspaceName(seed)
|
|
}
|
|
|
|
export function resolveWorkspaceCreateName(args: {
|
|
draft: string | undefined
|
|
fallback: string
|
|
}): string {
|
|
return args.draft?.trim() || args.fallback
|
|
}
|