(url)
| 71 | * @returns Parsed repository information |
| 72 | */ |
| 73 | const parseGitHubURL = (url) => { |
| 74 | // Splitting the pathname to get the repository details |
| 75 | const parts = url.pathname.split('/') |
| 76 | const pathLength = 4 |
| 77 | const isSubdirectory = parts.length > pathLength |
| 78 | const owner = parts[1] |
| 79 | const repo = parts[2] |
| 80 | const branch = isSubdirectory ? parts[pathLength] : 'master' |
| 81 | const isGitHubEnterprise = url.hostname !== 'github.com' |
| 82 | |
| 83 | // Validating GitHub URL if it's not a GitHub Enterprise URL |
| 84 | if (!isGitHubEnterprise) { |
| 85 | validateUrl({ url, hostname: 'github.com', service: 'GitHub', owner, repo }) |
| 86 | } |
| 87 | |
| 88 | // Constructing the download URL |
| 89 | const downloadUrl = `https://${isGitHubEnterprise ? url.hostname : 'github.com'}/${owner}/${repo}/archive/${branch}.zip` |
| 90 | |
| 91 | // Returning parsed repository information |
| 92 | return { |
| 93 | owner, |
| 94 | repo, |
| 95 | branch, |
| 96 | downloadUrl, |
| 97 | isSubdirectory, |
| 98 | pathToDirectory: getPathDirectory(pathLength + 1, parts), |
| 99 | username: url.username || '', |
| 100 | password: url.password || '', |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | /** |
| 105 | * Parse Bitbucket URL |
no test coverage detected
searching dependent graphs…