Socket
Socket
Sign inDemoInstall

download-git-repo

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

download-git-repo - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

test/fixtures/bitbucket/master/bar/README.md

128

index.js

@@ -1,4 +0,4 @@

var downloadUrl = require("download")
var gitclone = require("git-clone")
var rm = require("rimraf").sync
var downloadUrl = require('download')
var gitclone = require('git-clone')
var rm = require('rimraf').sync

@@ -21,3 +21,3 @@ /**

function download (repo, dest, opts, fn) {
if (typeof opts === "function") {
if (typeof opts === 'function') {
fn = opts

@@ -33,14 +33,12 @@ opts = null

if (clone) {
gitclone(url, dest, { checkout: repo.checkout }, function (err) {
gitclone(url, dest, { checkout: repo.checkout, shallow: repo.checkout === 'master' }, function (err) {
if (err === undefined) {
rm(dest + "/.git")
rm(dest + '/.git')
fn()
}
else {
} else {
fn(err)
}
})
}
else {
downloadUrl(url, dest, { extract: true, strip: 1, mode: "666", headers: { accept: "application/zip" } }).then(data => {
} else {
downloadUrl(url, dest, { extract: true, strip: 1, mode: '666', headers: { accept: 'application/zip' } }).then(data => {
fn()

@@ -63,15 +61,15 @@ }).catch(err => {

var match = regex.exec(repo)
var type = match[2] || "github"
var type = match[2] || 'github'
var origin = match[4] || null
var owner = match[5]
var name = match[6]
var checkout = match[8] || "master"
var checkout = match[8] || 'master'
if (origin == null) {
if (type === "github")
origin = "github.com"
else if (type === "gitlab")
origin = "gitlab.com"
else if (type === "bitbucket")
origin = "bitbucket.com"
if (type === 'github')
origin = 'github.com'
else if (type === 'gitlab')
origin = 'gitlab.com'
else if (type === 'bitbucket')
origin = 'bitbucket.com'
}

@@ -89,3 +87,3 @@

/**
* Add HTTPs protocol to url in none specified.
* Adds protocol to url in none specified
*

@@ -96,7 +94,11 @@ * @param {String} url

function addProtocol (url) {
if (!/^(f|ht)tps?:\/\//i.test(url))
url = "https://" + url
function addProtocol (origin, clone) {
if (!/^(f|ht)tps?:\/\//i.test(origin)) {
if (clone)
origin = 'git@' + origin
else
origin = 'https://' + origin
}
return url
return origin
}

@@ -114,66 +116,24 @@

if (repo.type === "github")
url = github(repo, clone)
else if (repo.type === "gitlab")
url = gitlab(repo, clone)
else if (repo.type === "bitbucket")
url = bitbucket(repo, clone)
// Get origin with protocol and add trailing slash or colon (for ssh)
var origin = addProtocol(repo.origin, clone)
if (/^git\@/i.test(origin))
origin = origin + ':'
else
url = github(repo, clone)
origin = origin + '/'
return url
}
// Build url
if (clone) {
url = origin + repo.owner + '/' + repo.name + '.git'
} else {
if (repo.type === 'github')
url = origin + repo.owner + '/' + repo.name + '/archive/' + repo.checkout + '.zip'
else if (repo.type === 'gitlab')
url = origin + repo.owner + '/' + repo.name + '/repository/archive.zip?ref=' + repo.checkout
else if (repo.type === 'bitbucket')
url = origin + repo.owner + '/' + repo.name + '/get/' + repo.checkout + '.zip'
else
url = github(repo)
}
/**
* Return a GitHub url for a given `repo` object.
*
* @param {Object} repo
* @return {String}
*/
function github (repo, clone) {
var url
if (clone)
url = "git@" + repo.origin + ":" + repo.owner + "/" + repo.name + ".git"
else
url = addProtocol(repo.origin) + "/" + repo.owner + "/" + repo.name + "/archive/" + repo.checkout + ".zip"
return url
}
/**
* Return a GitLab url for a given `repo` object.
*
* @param {Object} repo
* @return {String}
*/
function gitlab (repo, clone) {
var url
if (clone)
url = "git@" + repo.origin + ":" + repo.owner + "/" + repo.name + ".git"
else
url = addProtocol(repo.origin) + "/" + repo.owner + "/" + repo.name + "/repository/archive.zip?ref=" + repo.checkout
return url
}
/**
* Return a Bitbucket url for a given `repo` object.
*
* @param {Object} repo
* @return {String}
*/
function bitbucket (repo, clone) {
var url
if (clone)
url = "git@" + repo.origin + ":" + repo.owner + "/" + repo.name + ".git"
else
url = addProtocol(repo.origin) + "/" + repo.owner + "/" + repo.name + "/get/" + repo.checkout + ".zip"
return url
}
{
"name": "download-git-repo",
"version": "1.0.0",
"version": "1.0.1",
"license": "MIT",

@@ -5,0 +5,0 @@ "repository": "git://github.com/flipxfx/download-git-repo",

@@ -24,3 +24,3 @@ # download-git-repo

In addition to specifying the type of where to download, you can also specify a custom origin like `gitlab:custom.com:owner/name`.
Custom origin will default to HTTPS unless protocol is specified.
Custom origin will default to `https` or `git@` for http and clone downloads respectively, unless protocol is specified.
Feel free to submit an issue or pull request for additional origin options.

@@ -43,3 +43,3 @@

download('flipxfx/download-git-repo-fixture', 'test/tmp', function (err) {
console.log(err ? "Error" : "Success")
console.log(err ? 'Error' : 'Success')
})

@@ -50,7 +50,22 @@ ```

```javascript
download('flipxfx/download-git-repo-fixture#my-branch', 'test/tmp', function (err) {
console.log(err ? "Error" : "Success")
download('bitbucket:flipxfx/download-git-repo-fixture#my-branch', 'test/tmp', { clone: true }, function (err) {
console.log(err ? 'Error' : 'Success')
})
```
Using http download from GitLab repository with custom origin.
```javascript
download('gitlab:mygitlab.com:flipxfx/download-git-repo-fixture#my-branch', 'test/tmp', function (err) {
console.log(err ? 'Error' : 'Success')
})
```
Using clone download from GitLab repository with custom origin and protocol.
Note that the repository type (`github`, `gitlab` etc.) is not required if cloning from a custom origin.
```javascript
download('https://mygitlab.com:flipxfx/download-git-repo-fixture#my-branch', 'test/tmp', { clone: true }, function (err) {
console.log(err ? 'Error' : 'Success')
})
```
## Thanks

@@ -57,0 +72,0 @@

@@ -8,5 +8,2 @@ var assert = require('assert')

this.timeout(10000)
var filter = function (x) {
return x[0] !== '.' || x === ".git"
}

@@ -17,28 +14,15 @@ beforeEach(function () {

describe('via github', function () {
it('downloads the master branch by default', function (done) {
download('github:flipxfx/download-git-repo-fixture', 'test/tmp', function (err) {
if (err) return done(err)
var actual = read('test/tmp', filter)
var expected = read('test/fixtures/master')
assert.deepEqual(actual, expected)
done()
})
})
var filter = function (x) {
return x[0] !== '.' || x === '.git'
}
it('downloads branches too', function (done) {
download('github:flipxfx/download-git-repo-fixture#my-branch', 'test/tmp', function (err) {
if (err) return done(err)
var actual = read('test/tmp', filter)
var expected = read('test/fixtures/my-branch')
assert.deepEqual(actual, expected)
done()
})
})
var runStyle = function (type, style) {
var clone = false
if (style === 'clones') clone = true
it('downloads from github by default', function (done) {
download('flipxfx/download-git-repo-fixture', 'test/tmp', function (err) {
it(style + ' master branch by default', function (done) {
download(type + ':flipxfx/download-git-repo-fixture', 'test/tmp', { clone: clone }, function (err) {
if (err) return done(err)
var actual = read('test/tmp', filter)
var expected = read('test/fixtures/master')
var expected = read('test/fixtures/' + type + '/master')
assert.deepEqual(actual, expected)

@@ -49,7 +33,7 @@ done()

it('clones the master branch by default', function (done) {
download('github:flipxfx/download-git-repo-fixture', 'test/tmp', { clone: true }, function (err) {
it(style + ' a branch', function (done) {
download(type + ':flipxfx/download-git-repo-fixture#my-branch', 'test/tmp', { clone: clone }, function (err) {
if (err) return done(err)
var actual = read('test/tmp', filter)
var expected = read('test/fixtures/master')
var expected = read('test/fixtures/' + type + '/my-branch')
assert.deepEqual(actual, expected)

@@ -60,7 +44,7 @@ done()

it('clones branches too', function (done) {
download('github:flipxfx/download-git-repo-fixture#my-branch', 'test/tmp', { clone: true }, function (err) {
it(style + ' a branch with slashes', function (done) {
download(type + ':flipxfx/download-git-repo-fixture#my/branch/with/slashes', 'test/tmp', { clone: clone }, function (err) {
if (err) return done(err)
var actual = read('test/tmp', filter)
var expected = read('test/fixtures/my-branch')
var expected = read('test/fixtures/' + type + '/my-branch-with-slashes')
assert.deepEqual(actual, expected)

@@ -71,7 +55,7 @@ done()

it('downloads branches with slashes', function (done) {
download('github:flipxfx/download-git-repo-fixture#my/branch/with/slashes', 'test/tmp', function (err) {
it(style + ' master branch with specific origin', function (done) {
download(type + ':' + type + '.com:flipxfx/download-git-repo-fixture', 'test/tmp', { clone: clone }, function (err) {
if (err) return done(err)
var actual = read('test/tmp', filter)
var expected = read('test/fixtures/my-branch-with-slashes')
var expected = read('test/fixtures/' + type + '/master')
assert.deepEqual(actual, expected)

@@ -81,10 +65,8 @@ done()

})
})
describe('via gitlab', function () {
it('downloads the master branch by default', function (done) {
download('gitlab:flipxfx/download-git-repo-fixture', 'test/tmp', function (err) {
it(style + ' master branch with specific origin and protocol', function (done) {
download(type + ':https://' + type + '.com:flipxfx/download-git-repo-fixture', 'test/tmp', { clone: clone }, function (err) {
if (err) return done(err)
var actual = read('test/tmp', filter)
var expected = read('test/fixtures/master')
var expected = read('test/fixtures/' + type + '/master')
assert.deepEqual(actual, expected)

@@ -95,7 +77,14 @@ done()

it('downloads branches too', function (done) {
download('gitlab:flipxfx/download-git-repo-fixture#my-branch', 'test/tmp', function (err) {
}
var runType = function (type) {
runStyle(type, 'downloads')
runStyle(type, 'clones')
it('clones master branch with specific origin without type', function (done) {
download(type + '.com:flipxfx/download-git-repo-fixture', 'test/tmp', { clone: true }, function (err) {
if (err) return done(err)
var actual = read('test/tmp', filter)
var expected = read('test/fixtures/my-branch')
var expected = read('test/fixtures/' + type + '/master')
assert.deepEqual(actual, expected)

@@ -106,7 +95,7 @@ done()

it('clones the master branch by default', function (done) {
download('gitlab:flipxfx/download-git-repo-fixture', 'test/tmp', { clone: true }, function (err) {
it('clones master branch with specific origin and protocol without type', function (done) {
download('https://' + type + '.com:flipxfx/download-git-repo-fixture', 'test/tmp', { clone: true }, function (err) {
if (err) return done(err)
var actual = read('test/tmp', filter)
var expected = read('test/fixtures/master')
var expected = read('test/fixtures/' + type + '/master')
assert.deepEqual(actual, expected)

@@ -116,8 +105,12 @@ done()

})
}
it('clones branches too', function (done) {
download('gitlab:flipxfx/download-git-repo-fixture#my-branch', 'test/tmp', { clone: true }, function (err) {
describe('via github', function () {
runType('github')
it('downloads from github by default', function (done) {
download('flipxfx/download-git-repo-fixture', 'test/tmp', function (err) {
if (err) return done(err)
var actual = read('test/tmp', filter)
var expected = read('test/fixtures/my-branch')
var expected = read('test/fixtures/github/master')
assert.deepEqual(actual, expected)

@@ -127,7 +120,11 @@ done()

})
})
describe('via gitlab', function () {
runType('gitlab')
it('errors when trying to download private repo', function (done) {
download('gitlab:infinitesecond/for-my-flippy', 'test/tmp', function (err) {
if (err) {
if (err.message == "Response code 406 (Not Acceptable)")
if (err.message == 'Response code 406 (Not Acceptable)')
return done()

@@ -138,3 +135,3 @@ else

var actual = read('test/tmp', filter)
var expected = read('test/fixtures/master')
var expected = read('test/fixtures/gitlab/master')
assert.deepEqual(actual, expected)

@@ -147,42 +144,4 @@ done()

describe('via bitbucket', function () {
it('downloads the master branch by default', function (done) {
download('bitbucket:flipxfx/download-git-repo-fixture', 'test/tmp', function (err) {
if (err) return done(err)
var actual = read('test/tmp', filter)
var expected = read('test/fixtures/master')
assert.deepEqual(actual, expected)
done()
})
})
it('downloads branches too', function (done) {
download('bitbucket:flipxfx/download-git-repo-fixture#my-branch', 'test/tmp', function (err) {
if (err) return done(err)
var actual = read('test/tmp', filter)
var expected = read('test/fixtures/my-branch')
assert.deepEqual(actual, expected)
done()
})
})
it('clones the master branch by default', function (done) {
download('bitbucket:flipxfx/download-git-repo-fixture', 'test/tmp', { clone: true }, function (err) {
if (err) return done(err)
var actual = read('test/tmp', filter)
var expected = read('test/fixtures/master')
assert.deepEqual(actual, expected)
done()
})
})
it('clones branches too', function (done) {
download('bitbucket:flipxfx/download-git-repo-fixture#my-branch', 'test/tmp', { clone: true }, function (err) {
if (err) return done(err)
var actual = read('test/tmp', filter)
var expected = read('test/fixtures/my-branch')
assert.deepEqual(actual, expected)
done()
})
})
runType('bitbucket')
})
})
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc