MCPcopy Create free account
hub / github.com/anomalyco/opencode / parse

Function parse

packages/core/src/repository.ts:57–86  ·  view source on GitHub ↗
(input: string)

Source from the content-addressed store, hash-verified

55}
56
57export function parse(input: string): Reference | undefined {
58 const cleaned = normalizeInput(input)
59 if (!cleaned) return
60
61 const githubPrefixed = cleaned.match(/^github:([^/\s]+)\/([^/\s]+)$/)
62 if (githubPrefixed) return buildRemote({ host: "github.com", segments: [githubPrefixed[1], githubPrefixed[2]] })
63
64 if (!cleaned.includes("://")) {
65 const scp = cleaned.match(/^(?:[^@/\s]+@)?([^:/\s]+):(.+)$/)
66 if (scp) return buildRemote({ host: scp[1], segments: parts(scp[2]), remote: cleaned })
67
68 const direct = parts(cleaned)
69 if (direct.length >= 2 && hostLike(direct[0])) return buildRemote({ host: direct[0], segments: direct.slice(1) })
70 if (direct.length === 2) return buildRemote({ host: "github.com", segments: direct })
71 }
72
73 try {
74 const url = new URL(cleaned)
75 if (url.protocol === "file:") return buildFile({ url, remote: cleaned })
76 const segments = parts(url.pathname)
77 return buildRemote({
78 host: url.host,
79 segments,
80 remote: url.host === "github.com" ? githubRemote(segments.join("/")) : cleaned,
81 protocol: url.protocol,
82 })
83 } catch {
84 return
85 }
86}
87
88export function parseRemote(input: string): RemoteReference {
89 const reference = parse(input)

Callers 1

parseRemoteFunction · 0.70

Calls 6

buildRemoteFunction · 0.85
buildFileFunction · 0.85
normalizeInputFunction · 0.70
partsFunction · 0.70
hostLikeFunction · 0.70
githubRemoteFunction · 0.70

Tested by

no test coverage detected