MCPcopy Create free account
hub / github.com/IgorWarzocha/howcode / buildGitHubRepositoryLink

Function buildGitHubRepositoryLink

shared/github-repository-url.ts:20–43  ·  view source on GitHub ↗
(
  owner: string,
  repo: string,
  cloneProtocol: 'https' | 'ssh' = 'https',
)

Source from the content-addressed store, hash-verified

18}
19
20function buildGitHubRepositoryLink(
21 owner: string,
22 repo: string,
23 cloneProtocol: 'https' | 'ssh' = 'https',
24): GitHubRepositoryLink | null {
25 const cleanOwner = owner.trim()
26 const cleanRepo = cleanRepositoryName(repo)
27
28 if (!(githubPathSegmentPattern.test(cleanOwner) && githubPathSegmentPattern.test(cleanRepo))) {
29 return null
30 }
31
32 const httpsCloneUrl = `https://github.com/${cleanOwner}/${cleanRepo}.git`
33 const sshUrl = `git@github.com:${cleanOwner}/${cleanRepo}.git`
34
35 return {
36 owner: cleanOwner,
37 repo: cleanRepo,
38 cloneUrl: cloneProtocol === 'ssh' ? sshUrl : httpsCloneUrl,
39 sshUrl,
40 canonicalUrl: `https://github.com/${cleanOwner}/${cleanRepo}`,
41 folderName: cleanRepo,
42 }
43}
44
45export function parseGitHubRepositoryUrl(input: string): GitHubRepositoryLink | null {
46 const value = input.trim()

Callers 1

parseGitHubRepositoryUrlFunction · 0.85

Calls 1

cleanRepositoryNameFunction · 0.85

Tested by

no test coverage detected