MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / parseGitRemote

Function parseGitRemote

source code/utils/detectRepository.ts:89–126  ·  view source on GitHub ↗
(input: string)

Source from the content-addressed store, hash-verified

87 * Note: repo names can contain dots (e.g., cc.kurs.web)
88 */
89export function parseGitRemote(input: string): ParsedRepository | null {
90 const trimmed = input.trim()
91
92 // SSH format: git@host:owner/repo.git
93 const sshMatch = trimmed.match(/^git@([^:]+):([^/]+)\/([^/]+?)(?:\.git)?$/)
94 if (sshMatch?.[1] && sshMatch[2] && sshMatch[3]) {
95 if (!looksLikeRealHostname(sshMatch[1])) return null
96 return {
97 host: sshMatch[1],
98 owner: sshMatch[2],
99 name: sshMatch[3],
100 }
101 }
102
103 // URL format: https://host/owner/repo.git, ssh://git@host/owner/repo, git://host/owner/repo
104 const urlMatch = trimmed.match(
105 /^(https?|ssh|git):\/\/(?:[^@]+@)?([^/:]+(?::\d+)?)\/([^/]+)\/([^/]+?)(?:\.git)?$/,
106 )
107 if (urlMatch?.[1] && urlMatch[2] && urlMatch[3] && urlMatch[4]) {
108 const protocol = urlMatch[1]
109 const hostWithPort = urlMatch[2]
110 const hostWithoutPort = hostWithPort.split(':')[0] ?? ''
111 if (!looksLikeRealHostname(hostWithoutPort)) return null
112 // Only preserve port for HTTPS — SSH/git ports are not usable for constructing
113 // web URLs (e.g. ssh://git@ghe.corp.com:2222 → port 2222 is SSH, not HTTPS).
114 const host =
115 protocol === 'https' || protocol === 'http'
116 ? hostWithPort
117 : hostWithoutPort
118 return {
119 host,
120 owner: urlMatch[3],
121 name: urlMatch[4],
122 }
123 }
124
125 return null
126}
127
128/**
129 * Parses a git remote URL or "owner/repo" string and returns "owner/repo".

Callers 6

getGithubRepoFunction · 0.85
parseGitHubRepositoryFunction · 0.85
createBridgeSessionFunction · 0.85
getCurrentRepoHttpsUrlFunction · 0.85

Calls 1

looksLikeRealHostnameFunction · 0.85

Tested by

no test coverage detected