(input: string)
| 137 | } |
| 138 | |
| 139 | export 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 | |
| 178 | export function isFileRepositoryReference(reference: Reference): reference is FileReference { |
| 179 | return reference.protocol === "file:" |
no test coverage detected