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

Function convertGitUrlToHttps

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

Source from the content-addressed store, hash-verified

85 * @returns The URL in HTTPS format, or the original URL if conversion is not possible
86 */
87export function convertGitUrlToHttps(url: string): string {
88 try {
89 // Already HTTPS, just return it
90 if (url.startsWith("https://")) {
91 return url
92 }
93
94 // Handle SSH format: git@github.com:user/repo.git -> https://github.com/user/repo.git
95 if (url.startsWith("git@")) {
96 const match = url.match(/git@([^:]+):(.+)/)
97 if (match && match.length === 3) {
98 const [, host, path] = match
99 return `https://${host}/${path}`
100 }
101 }
102
103 // Handle SSH with protocol: ssh://git@github.com/user/repo.git -> https://github.com/user/repo.git
104 if (url.startsWith("ssh://")) {
105 const match = url.match(/ssh:\/\/(?:git@)?([^\/]+)\/(.+)/)
106 if (match && match.length === 3) {
107 const [, host, path] = match
108 return `https://${host}/${path}`
109 }
110 }
111
112 // Return original URL if we can't convert it
113 return url
114 } catch {
115 // If parsing fails, return original
116 return url
117 }
118}
119
120/**
121 * Sanitizes a git URL to remove sensitive information like tokens

Callers 2

git.spec.tsFile · 0.90
getGitRepositoryInfoFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected