MCPcopy Create free account
hub / github.com/Zoo-Code-Org/Zoo-Code / extractRepositoryName

Function extractRepositoryName

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

Source from the content-addressed store, hash-verified

152 * @returns Repository name or undefined
153 */
154export function extractRepositoryName(url: string): string {
155 try {
156 // Handle different URL formats
157 const patterns = [
158 // HTTPS: https://github.com/user/repo.git -> user/repo
159 /https:\/\/[^\/]+\/([^\/]+\/[^\/]+?)(?:\.git)?$/,
160 // SSH: git@github.com:user/repo.git -> user/repo
161 /git@[^:]+:([^\/]+\/[^\/]+?)(?:\.git)?$/,
162 // SSH with user: ssh://git@github.com/user/repo.git -> user/repo
163 /ssh:\/\/[^\/]+\/([^\/]+\/[^\/]+?)(?:\.git)?$/,
164 ]
165
166 for (const pattern of patterns) {
167 const match = url.match(pattern)
168 if (match && match[1]) {
169 return match[1].replace(/\.git$/, "")
170 }
171 }
172
173 return ""
174 } catch {
175 return ""
176 }
177}
178
179/**
180 * Gets git repository information for the current VSCode workspace

Callers 2

git.spec.tsFile · 0.90
getGitRepositoryInfoFunction · 0.85

Calls 1

replaceMethod · 0.65

Tested by

no test coverage detected