(input: { host: string; segments: string[]; remote?: string; protocol?: string })
| 172 | } |
| 173 | |
| 174 | function buildRemote(input: { host: string; segments: string[]; remote?: string; protocol?: string }) { |
| 175 | const segments = input.segments.map(trimGitSuffix).filter(Boolean) |
| 176 | if (!safeHost(input.host) || !segments.length || segments.some((segment) => !safeSegment(segment))) return |
| 177 | const repositoryPath = segments.join("/") |
| 178 | const host = input.host.toLowerCase() |
| 179 | return { |
| 180 | host, |
| 181 | path: repositoryPath, |
| 182 | segments, |
| 183 | owner: segments.length === 2 ? segments[0] : undefined, |
| 184 | repo: segments[segments.length - 1], |
| 185 | remote: |
| 186 | input.remote ?? (host === "github.com" ? githubRemote(repositoryPath) : `https://${host}/${repositoryPath}.git`), |
| 187 | label: host === "github.com" && segments.length === 2 ? repositoryPath : `${host}/${repositoryPath}`, |
| 188 | protocol: input.protocol, |
| 189 | } satisfies RemoteReference |
| 190 | } |
| 191 | |
| 192 | function buildFile(input: { url: URL; remote: string }) { |
| 193 | const filePath = path.normalize(fileURLToPath(input.url)) |
no test coverage detected