MCPcopy Create free account
hub / github.com/dyoshikawa/rulesync / parseSource

Function parseSource

src/lib/source-parser.ts:18–43  ·  view source on GitHub ↗
(source: string)

Source from the content-addressed store, hash-verified

16 * - Combined: owner/repo@ref:path
17 */
18export 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

Callers 5

fetch.test.tsFile · 0.85
fetchSourceFunction · 0.85
fetchFilesFunction · 0.85
resolveGhSourceFunction · 0.85

Calls 2

parseUrlFunction · 0.85
parseShorthandFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…