Leo Lamprecht
8 years ago
No known key found for this signature in database
GPG Key ID: B08517883D5E0E10
1 changed files with
23 additions and
4 deletions
-
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 => { |
|
|
|