(source: string)
| 16 | * - Combined: owner/repo@ref:path |
| 17 | */ |
| 18 | export function parseSource(source: string): ParsedSource { |
| 19 | // Handle full URL format (https://...) |
| 20 | if (source.startsWith("http://") || source.startsWith("https://")) { |
| 21 | return parseUrl(source); |
| 22 | } |
| 23 | |
| 24 | // Handle prefix format (github:owner/repo, gitlab:owner/repo) |
| 25 | if (source.includes(":") && !source.includes("://")) { |
| 26 | const colonIndex = source.indexOf(":"); |
| 27 | const prefix = source.substring(0, colonIndex); |
| 28 | const rest = source.substring(colonIndex + 1); |
| 29 | |
| 30 | // Check if prefix is a known provider using type guard |
| 31 | const provider = ALL_GIT_PROVIDERS.find((p) => p === prefix); |
| 32 | if (provider) { |
| 33 | return { provider, ...parseShorthand(rest) }; |
| 34 | } |
| 35 | |
| 36 | // If prefix is not a known provider, treat the whole thing as shorthand |
| 37 | // This handles cases like owner/repo:path where "owner/repo" contains no provider prefix |
| 38 | return { provider: "github", ...parseShorthand(source) }; |
| 39 | } |
| 40 | |
| 41 | // Handle shorthand: owner/repo[@ref][:path] - defaults to GitHub |
| 42 | return { provider: "github", ...parseShorthand(source) }; |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * Parse URL format into components |
no test coverage detected
searching dependent graphs…