( owner: string, repo: string, cloneProtocol: 'https' | 'ssh' = 'https', )
| 18 | } |
| 19 | |
| 20 | function 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 | |
| 45 | export function parseGitHubRepositoryUrl(input: string): GitHubRepositoryLink | null { |
| 46 | const value = input.trim() |
no test coverage detected