MCPcopy Create free account
hub / github.com/CodeGraphContext/CodeGraphContext / parseRepoInput

Function parseRepoInput

website/src/lib/repo-provider.ts:30–80  ·  view source on GitHub ↗
(input: string)

Source from the content-addressed store, hash-verified

28
29/** Parse a user-supplied URL or `owner/repo` shorthand into a RepoRef. */
30export function parseRepoInput(input: string): RepoRef | null {
31 const trimmed = input.trim();
32 if (!trimmed) return null;
33
34 const gitlabMatch = trimmed.match(/gitlab\.com\/([^?#]+)/i);
35 if (gitlabMatch) {
36 const path = cleanRepoPathSegment(gitlabMatch[1]);
37 const parts = path.split("/").filter(Boolean);
38 if (parts.length < 2) return null;
39 const repo = parts[parts.length - 1];
40 const owner = parts.slice(0, -1).join("/");
41 return {
42 provider: "gitlab",
43 owner,
44 repo,
45 fullPath: `${owner}/${repo}`,
46 host: GITLAB_HOST,
47 };
48 }
49
50 const githubMatch = trimmed.match(/github\.com\/([^/]+)\/([^/?#]+)/i);
51 if (githubMatch) {
52 const owner = githubMatch[1];
53 const repo = githubMatch[2].replace(/\.git$/, "");
54 return {
55 provider: "github",
56 owner,
57 repo,
58 fullPath: `${owner}/${repo}`,
59 host: GITHUB_HOST,
60 };
61 }
62
63 const shorthand = trimmed.match(/^([^/]+\/[^/]+(?:\/[^/]+)*)\/?$/);
64 if (shorthand) {
65 const path = cleanRepoPathSegment(shorthand[1]);
66 const parts = path.split("/").filter(Boolean);
67 if (parts.length < 2) return null;
68 const repo = parts[parts.length - 1];
69 const owner = parts.slice(0, -1).join("/");
70 return {
71 provider: "github",
72 owner,
73 repo,
74 fullPath: `${owner}/${repo}`,
75 host: GITHUB_HOST,
76 };
77 }
78
79 return null;
80}
81
82/** Build a RepoRef from route parameters. */
83export function repoRefFromRoute(

Callers 1

handleRemoteRepoFetchFunction · 0.90

Calls 1

cleanRepoPathSegmentFunction · 0.85

Tested by

no test coverage detected