(input: { host: string; segments: string[]; remote?: string; protocol?: string })
| 103 | } |
| 104 | |
| 105 | function buildRemoteReference(input: { host: string; segments: string[]; remote?: string; protocol?: string }) { |
| 106 | const segments = input.segments.map(trimGitSuffix).filter(Boolean) |
| 107 | if (!safeHost(input.host) || !segments.length || segments.some((segment) => !safeSegment(segment))) return null |
| 108 | const pathname = segments.join("/") |
| 109 | const repo = segments[segments.length - 1] |
| 110 | const host = input.host.toLowerCase() |
| 111 | return { |
| 112 | host, |
| 113 | path: pathname, |
| 114 | segments, |
| 115 | owner: segments.length === 2 ? segments[0] : undefined, |
| 116 | repo, |
| 117 | remote: input.remote ?? (host === "github.com" ? githubRemote(pathname) : `https://${host}/${pathname}.git`), |
| 118 | label: host === "github.com" && segments.length === 2 ? pathname : `${host}/${pathname}`, |
| 119 | protocol: input.protocol, |
| 120 | } satisfies RemoteReference |
| 121 | } |
| 122 | |
| 123 | function buildFileReference(input: { url: URL; remote: string }) { |
| 124 | const filePath = path.normalize(fileURLToPath(input.url)) |
no test coverage detected