Browse Source

Accept GitLab URLs

master
Leo Lamprecht 8 years ago
parent
commit
77412000ca
No known key found for this signature in database GPG Key ID: B08517883D5E0E10
  1. 27
      lib/github.js

27
lib/github.js

@ -10,7 +10,16 @@ import isURL from 'is-url'
const downloadRepo = async repoPath => { const downloadRepo = async repoPath => {
const pathParts = gitPathParts(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({ const tmpDir = await tmp.dir({
// We'll remove it manually once deployment is done // We'll remove it manually once deployment is done
@ -35,7 +44,9 @@ const downloadRepo = async repoPath => {
} }
const splittedURL = fullURL => { const splittedURL = fullURL => {
const pathParts = url.parse(fullURL).path.split('/') const parsedURL = url.parse(fullURL)
const pathParts = parsedURL.path.split('/')
pathParts.shift() pathParts.shift()
// Set path to repo... // Set path to repo...
@ -58,7 +69,11 @@ const splittedURL = fullURL => {
ref = '' ref = ''
} }
return {main, ref} return {
main,
ref,
type: parsedURL.host.split('.')[0]
}
} }
export const gitPathParts = main => { export const gitPathParts = main => {
@ -75,7 +90,11 @@ export const gitPathParts = main => {
main = parts[0] main = parts[0]
} }
return {main, ref} return {
main,
ref,
type: 'github'
}
} }
export const isRepoPath = path => { export const isRepoPath = path => {

Loading…
Cancel
Save