(inputUrl)
| 275 | * @returns A Promise |
| 276 | */ |
| 277 | export const parseRepoURL = async (inputUrl) => { |
| 278 | if (!inputUrl) { |
| 279 | return new Error('URL is required') |
| 280 | } |
| 281 | |
| 282 | const url = parseUrl(inputUrl.replace(/\/$/, '')) |
| 283 | if (url.auth) { |
| 284 | const [username, password] = url.auth.split(':') |
| 285 | url.username = username |
| 286 | url.password = password |
| 287 | } |
| 288 | |
| 289 | // check if url parameter is a valid url |
| 290 | if (!url.host && !url.href.startsWith('git@')) { |
| 291 | return new Error('The URL you passed is not valid') |
| 292 | } |
| 293 | |
| 294 | if (isPlainGitURL(url.href)) { |
| 295 | return parsePlainGitURL(inputUrl) |
| 296 | } else if ( |
| 297 | url.hostname === 'github.com' || |
| 298 | url.hostname.includes('github.') |
| 299 | ) { |
| 300 | return parseGitHubURL(url) |
| 301 | } else if (url.hostname === 'bitbucket.org') { |
| 302 | return parseBitbucketURL(url) |
| 303 | } else if (url.hostname === 'gitlab.com') { |
| 304 | return parseGitlabURL(url) |
| 305 | } |
| 306 | |
| 307 | // Check if it's a private Bitbucket server |
| 308 | const msg = |
| 309 | 'The URL you passed is not one of the valid providers: "GitHub", "GitHub Entreprise", "Bitbucket", "Bitbucket Server" or "GitLab".' |
| 310 | const err = new Error(msg) |
| 311 | const isBitbucket = await retrieveBitbucketServerInfo(url) |
| 312 | if (!isBitbucket) { |
| 313 | throw err |
| 314 | } |
| 315 | |
| 316 | // build download URL |
| 317 | let parsedBitbucketServerURL |
| 318 | try { |
| 319 | parsedBitbucketServerURL = parseBitbucketServerURL(url) |
| 320 | } catch (error) { |
| 321 | throw err |
| 322 | } |
| 323 | return parsedBitbucketServerURL |
| 324 | } |
| 325 | |
| 326 | /** |
| 327 | * Download template from repository |
no test coverage detected
searching dependent graphs…