MCPcopy Create free account
hub / github.com/Noumena-Network/code / normalizeGitRemoteUrl

Function normalizeGitRemoteUrl

src/utils/git.ts:298–336  ·  view source on GitHub ↗
(url: string)

Source from the content-addressed store, hash-verified

296 * - http://local_proxy@127.0.0.1:16583/git/owner/repo -> github.com/owner/repo
297 */
298export function normalizeGitRemoteUrl(url: string): string | null {
299 const trimmed = url.trim()
300 if (!trimmed) return null
301
302 // Handle SSH format: git@host:owner/repo.git
303 const sshMatch = trimmed.match(/^git@([^:]+):(.+?)(?:\.git)?$/)
304 if (sshMatch && sshMatch[1] && sshMatch[2]) {
305 return `${sshMatch[1]}/${sshMatch[2]}`.toLowerCase()
306 }
307
308 // Handle HTTPS/SSH URL format: https://host/owner/repo.git or ssh://git@host/owner/repo
309 const urlMatch = trimmed.match(
310 /^(?:https?|ssh):\/\/(?:[^@]+@)?([^/]+)\/(.+?)(?:\.git)?$/,
311 )
312 if (urlMatch && urlMatch[1] && urlMatch[2]) {
313 const host = urlMatch[1]
314 const path = urlMatch[2]
315
316 // CCR git proxy URLs use format:
317 // Legacy: http://...@127.0.0.1:PORT/git/owner/repo (github.com assumed)
318 // GHE: http://...@127.0.0.1:PORT/git/ghe.host/owner/repo (host encoded in path)
319 // Strip the /git/ prefix. If the first segment contains a dot, it's a
320 // hostname (GitHub org names cannot contain dots). Otherwise assume github.com.
321 if (isLocalHost(host) && path.startsWith('git/')) {
322 const proxyPath = path.slice(4) // Remove "git/" prefix
323 const segments = proxyPath.split('/')
324 // 3+ segments where first contains a dot → host/owner/repo (GHE format)
325 if (segments.length >= 3 && segments[0]!.includes('.')) {
326 return proxyPath.toLowerCase()
327 }
328 // 2 segments → owner/repo (legacy format, assume github.com)
329 return `github.com/${proxyPath}`.toLowerCase()
330 }
331
332 return `${host}/${path}`.toLowerCase()
333 }
334
335 return null
336}
337
338/**
339 * Returns a SHA256 hash (first 16 chars) of the normalized git remote URL.

Callers 1

getRepoRemoteHashFunction · 0.85

Calls 1

isLocalHostFunction · 0.85

Tested by

no test coverage detected