Showing the changes to apps/server/src/sourceControl/SourceControlProvider.ts (1 of 59 files). Show all
Unified · Split
| @@ -21,6 +21,33 @@ export interface SourceControlRefSelector { · 20 unmodified lines | |||
| 21 | readonly repository?: string; | 21 | readonly repository?: string; |
| 22 | } | 22 | } |
| 23 | 23 | ||
| 24 | export function parseSourceControlOwnerRef( | ||
| 25 | headSelector: string, | ||
| 26 | ): SourceControlRefSelector | undefined { | ||
| 27 | const match = /^([^:/\s]+):(.+)$/u.exec(headSelector.trim()); | ||
| 28 | const owner = match?.[1]?.trim(); | ||
| 29 | const refName = match?.[2]?.trim(); | ||
| 30 | return owner && refName ? { owner, refName } : undefined; | ||
| 31 | } | ||
| 32 | |||
| 33 | export function normalizeSourceBranch(headSelector: string): string { | ||
| 34 | return parseSourceControlOwnerRef(headSelector)?.refName ?? headSelector.trim(); | ||
| 35 | } | ||
| 36 | |||
| 37 | export function sourceBranch(input: { | ||
| 38 | readonly headSelector: string; | ||
| 39 | readonly source?: SourceControlRefSelector; | ||
| 40 | }): string { | ||
| 41 | return input.source?.refName ?? normalizeSourceBranch(input.headSelector); | ||
| 42 | } | ||
| 43 | |||
| 44 | export function sourceControlRefFromInput(input: { | ||
| 45 | readonly headSelector: string; | ||
| 46 | readonly source?: SourceControlRefSelector; | ||
| 47 | }): SourceControlRefSelector | undefined { | ||
| 48 | return input.source ?? parseSourceControlOwnerRef(input.headSelector); | ||
| 49 | } | ||
| 50 | |||
| 24 | export interface SourceControlProviderShape { | 51 | export interface SourceControlProviderShape { |
| 25 | readonly kind: SourceControlProviderKind; | 52 | readonly kind: SourceControlProviderKind; |
| 26 | readonly listChangeRequests: (input: { | 53 | readonly listChangeRequests: (input: { |