Skip to content

Commit

Permalink
Accept GitLab URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
leo committed Nov 28, 2016
1 parent a63924f commit 7741200
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions lib/github.js
Expand Up @@ -10,7 +10,16 @@ import isURL from 'is-url'

const downloadRepo = async repoPath => {
const pathParts = gitPathParts(repoPath)
const url = `https://api.github.com/repos/${pathParts.main}/tarball/${pathParts.ref}`
let url

switch (pathParts.type) {
case 'gitlab':
const ref = pathParts.ref ? `?ref=${pathParts.ref}` : ''
url = `https://gitlab.com/${pathParts.main}/repository/archive.tar` + ref
break
default:
url = `https://api.github.com/repos/${pathParts.main}/tarball/${pathParts.ref}`
}

const tmpDir = await tmp.dir({
// We'll remove it manually once deployment is done
Expand All @@ -35,7 +44,9 @@ const downloadRepo = async repoPath => {
}

const splittedURL = fullURL => {
const pathParts = url.parse(fullURL).path.split('/')
const parsedURL = url.parse(fullURL)
const pathParts = parsedURL.path.split('/')

pathParts.shift()

// Set path to repo...
Expand All @@ -58,7 +69,11 @@ const splittedURL = fullURL => {
ref = ''
}

return {main, ref}
return {
main,
ref,
type: parsedURL.host.split('.')[0]
}
}

export const gitPathParts = main => {
Expand All @@ -75,7 +90,11 @@ export const gitPathParts = main => {
main = parts[0]
}

return {main, ref}
return {
main,
ref,
type: 'github'
}
}

export const isRepoPath = path => {
Expand Down

0 comments on commit 7741200

Please sign in to comment.