MCPcopy Index your code
hub / github.com/lingodotdev/lingo.dev / parseGitUrl

Function parseGitUrl

packages/cli/src/cli/utils/org-id.ts:70–103  ·  view source on GitHub ↗
(url: string)

Source from the content-addressed store, hash-verified

68}
69
70function parseGitUrl(url: string): string | null {
71 const cleanUrl = url.replace(/\.git$/, "");
72
73 const host = cleanUrl
74 .replace(/^[a-z][a-z0-9+.-]*:\/\//i, "") // strip scheme://
75 .replace(/^[^@/]+@/, "") // strip user@
76 .split(/[/:]/)[0] // host token, before first / or :
77 .toLowerCase();
78
79 let platform: string | null = null;
80 if (host === "github.com" || host.endsWith(".github.com")) {
81 platform = "github";
82 } else if (host === "gitlab.com" || host.endsWith(".gitlab.com")) {
83 platform = "gitlab";
84 } else if (host === "bitbucket.org" || host.endsWith(".bitbucket.org")) {
85 platform = "bitbucket";
86 }
87
88 const sshMatch = cleanUrl.match(/[@:]([^:/@]+\/[^:/@]+)$/);
89 const httpsMatch = cleanUrl.match(/\/([^/]+\/[^/]+)$/);
90
91 const repoPath = sshMatch?.[1] || httpsMatch?.[1];
92
93 if (!repoPath) return null;
94
95 const org = extractOrg(repoPath);
96 if (!org) return null;
97
98 if (platform) {
99 return `${platform}:${org}`;
100 }
101
102 return `git:${org}`;
103}

Callers 1

getGitOrgIdFunction · 0.70

Calls 1

extractOrgFunction · 0.70

Tested by

no test coverage detected