MCPcopy Index your code
hub / github.com/anomalyco/opencode / parseRepositoryReference

Function parseRepositoryReference

packages/opencode/src/util/repository.ts:139–176  ·  view source on GitHub ↗
(input: string)

Source from the content-addressed store, hash-verified

137}
138
139export function parseRepositoryReference(input: string) {
140 const cleaned = normalizeRepositoryInput(input)
141 if (!cleaned) return null
142
143 const githubPrefixed = cleaned.match(/^github:([^/\s]+)\/([^/\s]+)$/)
144 if (githubPrefixed) {
145 return buildRemoteReference({ host: "github.com", segments: [githubPrefixed[1], githubPrefixed[2]] })
146 }
147
148 if (!cleaned.includes("://")) {
149 const scp = cleaned.match(/^(?:[^@/\s]+@)?([^:/\s]+):(.+)$/)
150 if (scp) return buildRemoteReference({ host: scp[1], segments: parts(scp[2]), remote: cleaned })
151
152 const direct = parts(cleaned)
153 if (direct.length >= 2 && hostLike(direct[0])) {
154 return buildRemoteReference({ host: direct[0], segments: direct.slice(1) })
155 }
156
157 if (direct.length === 2) {
158 return buildRemoteReference({ host: "github.com", segments: direct })
159 }
160 }
161
162 try {
163 const url = new URL(cleaned)
164 if (url.protocol === "file:") return buildFileReference({ url, remote: cleaned })
165 const pathname = parts(url.pathname)
166 const host = url.host
167 return buildRemoteReference({
168 host,
169 segments: pathname,
170 remote: host === "github.com" ? githubRemote(pathname.join("/")) : cleaned,
171 protocol: url.protocol,
172 })
173 } catch {
174 return null
175 }
176}
177
178export function isFileRepositoryReference(reference: Reference): reference is FileReference {
179 return reference.protocol === "file:"

Callers 3

repository.test.tsFile · 0.90
parseGitHubRemoteFunction · 0.85

Calls 6

normalizeRepositoryInputFunction · 0.85
buildRemoteReferenceFunction · 0.85
buildFileReferenceFunction · 0.85
partsFunction · 0.70
hostLikeFunction · 0.70
githubRemoteFunction · 0.70

Tested by

no test coverage detected