MCPcopy Create free account
hub / github.com/AsyncFuncAI/deepwiki-open / parseRepositoryInput

Function parseRepositoryInput

src/app/page.tsx:177–246  ·  view source on GitHub ↗
(input: string)

Source from the content-addressed store, hash-verified

175
176 // Parse repository URL/input and extract owner and repo
177 const parseRepositoryInput = (input: string): {
178 owner: string,
179 repo: string,
180 type: string,
181 fullPath?: string,
182 localPath?: string
183 } | null => {
184 input = input.trim();
185
186 let owner = '', repo = '', type = 'github', fullPath;
187 let localPath: string | undefined;
188
189 // Handle Windows absolute paths (e.g., C:\path\to\folder)
190 const windowsPathRegex = /^[a-zA-Z]:\\(?:[^\\/:*?"<>|\r\n]+\\)*[^\\/:*?"<>|\r\n]*$/;
191 const customGitRegex = /^(?:https?:\/\/)?([^\/]+)\/(.+?)\/([^\/]+)(?:\.git)?\/?$/;
192
193 if (windowsPathRegex.test(input)) {
194 type = 'local';
195 localPath = input;
196 repo = input.split('\\').pop() || 'local-repo';
197 owner = 'local';
198 }
199 // Handle Unix/Linux absolute paths (e.g., /path/to/folder)
200 else if (input.startsWith('/')) {
201 type = 'local';
202 localPath = input;
203 repo = input.split('/').filter(Boolean).pop() || 'local-repo';
204 owner = 'local';
205 }
206 else if (customGitRegex.test(input)) {
207 // Detect repository type based on domain
208 const domain = extractUrlDomain(input);
209 if (domain?.includes('github.com')) {
210 type = 'github';
211 } else if (domain?.includes('gitlab.com') || domain?.includes('gitlab.')) {
212 type = 'gitlab';
213 } else if (domain?.includes('bitbucket.org') || domain?.includes('bitbucket.')) {
214 type = 'bitbucket';
215 } else {
216 type = 'web'; // fallback for other git hosting services
217 }
218
219 fullPath = extractUrlPath(input)?.replace(/\.git$/, '');
220 const parts = fullPath?.split('/') ?? [];
221 if (parts.length >= 2) {
222 repo = parts[parts.length - 1] || '';
223 owner = parts[parts.length - 2] || '';
224 }
225 }
226 // Unsupported URL formats
227 else {
228 console.error('Unsupported URL format:', input);
229 return null;
230 }
231
232 if (!owner || !repo) {
233 return null;
234 }

Callers 2

handleFormSubmitFunction · 0.85
handleGenerateWikiFunction · 0.85

Calls 3

extractUrlDomainFunction · 0.90
extractUrlPathFunction · 0.90
filterMethod · 0.80

Tested by

no test coverage detected