diff --git a/lib/github.js b/lib/github.js index 3df8000..aed7bdc 100644 --- a/lib/github.js +++ b/lib/github.js @@ -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 @@ -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... @@ -58,7 +69,11 @@ const splittedURL = fullURL => { ref = '' } - return {main, ref} + return { + main, + ref, + type: parsedURL.host.split('.')[0] + } } export const gitPathParts = main => { @@ -75,7 +90,11 @@ export const gitPathParts = main => { main = parts[0] } - return {main, ref} + return { + main, + ref, + type: 'github' + } } export const isRepoPath = path => {