Leo Lamprecht
8 years ago
No known key found for this signature in database
GPG Key ID: B08517883D5E0E10
2 changed files with
34 additions and
0 deletions
-
lib/github.js
-
package.json
|
|
@ -1,13 +1,16 @@ |
|
|
|
// Native
|
|
|
|
import path from 'path' |
|
|
|
import url from 'url' |
|
|
|
|
|
|
|
// Packages
|
|
|
|
import fs from 'fs-promise' |
|
|
|
import download from 'download' |
|
|
|
import tmp from 'tmp-promise' |
|
|
|
import isURL from 'is-url' |
|
|
|
|
|
|
|
const downloadRepo = async repoPath => { |
|
|
|
const pathParts = gitPathParts(repoPath) |
|
|
|
console.log(pathParts) |
|
|
|
const url = `https://api.github.com/repos/${pathParts.main}/tarball/${pathParts.ref}` |
|
|
|
|
|
|
|
const tmpDir = await tmp.dir({ |
|
|
@ -32,9 +35,29 @@ const downloadRepo = async repoPath => { |
|
|
|
return tmpDir |
|
|
|
} |
|
|
|
|
|
|
|
const splittedURL = fullURL => { |
|
|
|
const pathParts = url.parse(fullURL).path.split('/') |
|
|
|
pathParts.shift() |
|
|
|
|
|
|
|
// Set path to repo...
|
|
|
|
const main = pathParts[0] + '/' + pathParts[1] |
|
|
|
|
|
|
|
// ...and then remove it from the parts
|
|
|
|
pathParts.splice(0, 2) |
|
|
|
|
|
|
|
return { |
|
|
|
main, |
|
|
|
ref: pathParts.length >= 2 ? pathParts[1] : '' |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
export const gitPathParts = main => { |
|
|
|
let ref = '' |
|
|
|
|
|
|
|
if (isURL(main)) { |
|
|
|
return splittedURL(main) |
|
|
|
} |
|
|
|
|
|
|
|
if (main.split('/')[1].includes('#')) { |
|
|
|
const parts = main.split('#') |
|
|
|
|
|
|
@ -50,6 +73,16 @@ export const isRepoPath = path => { |
|
|
|
return false |
|
|
|
} |
|
|
|
|
|
|
|
if (isURL(path)) { |
|
|
|
const urlParts = url.parse(path) |
|
|
|
const slashCount = (urlParts.path.match(new RegExp('/', 'g')) || []).length |
|
|
|
const notBare = slashCount >= 2 |
|
|
|
|
|
|
|
if (urlParts.host === 'github.com' && notBare) { |
|
|
|
return true |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return /[^\s\\]\/[^\s\\]/g.test(path) |
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -81,6 +81,7 @@ |
|
|
|
"graceful-fs": "4.1.11", |
|
|
|
"ignore": "3.2.0", |
|
|
|
"ini": "1.3.4", |
|
|
|
"is-url": "1.2.2", |
|
|
|
"minimist": "1.2.0", |
|
|
|
"ms": "0.7.2", |
|
|
|
"node-fetch": "1.6.3", |
|
|
|