MCPcopy
hub / github.com/npmx-dev/npmx.dev / parseRepositoryInfo

Function parseRepositoryInfo

shared/utils/git-providers.ts:323–352  ·  view source on GitHub ↗
(
  repository?: { type?: string; url?: string; directory?: string } | string,
)

Source from the content-addressed store, hash-verified

321 * Supports both full objects and shorthand strings.
322 */
323export function parseRepositoryInfo(
324 repository?: { type?: string; url?: string; directory?: string } | string,
325): RepositoryInfo | undefined {
326 if (!repository) return undefined
327
328 let url: string | undefined
329 let directory: string | undefined
330
331 if (typeof repository === 'string') {
332 url = repository
333 } else {
334 url = repository.url
335 directory = repository.directory
336 }
337
338 if (!url) return undefined
339
340 const ref = parseRepoUrl(url)
341 if (!ref) return undefined
342
343 const provider = providers.find(p => p.id === ref.provider)
344 if (!provider) return undefined
345
346 return {
347 ...ref,
348 rawBaseUrl: provider.getRawBaseUrl(ref),
349 blobBaseUrl: provider.getBlobBaseUrl(ref),
350 directory: directory ? withoutTrailingSlash(directory) : undefined,
351 }
352}
353
354export function getProviderConfig(providerId: ProviderId): ProviderConfig | undefined {
355 return providers.find(p => p.id === providerId)

Callers 4

fetchPackagesFunction · 0.85
readme-loaders.tsFile · 0.85
[...pkg].get.tsFile · 0.85

Calls 3

parseRepoUrlFunction · 0.85
getRawBaseUrlMethod · 0.80
getBlobBaseUrlMethod · 0.80

Tested by

no test coverage detected