github-url-to-object
Advanced tools
Comparing version 2.2.1 to 2.2.2
18
index.js
@@ -7,10 +7,11 @@ 'use strict' | ||
module.exports = function (repo_url) { | ||
module.exports = function (repoUrl, opts) { | ||
var obj = {} | ||
opts = opts || {} | ||
if (!repo_url) return null | ||
if (!repoUrl) return null | ||
var shorthand = repo_url.match(/^([\w-_]+)\/([\w-_\.]+)#?([\w-_\.]+)?$/) | ||
var mediumhand = repo_url.match(/^github:([\w-_]+)\/([\w-_\.]+)#?([\w-_\.]+)?$/) | ||
var antiquated = repo_url.match(/^git@[\w-_\.]+:([\w-_]+)\/([\w-_\.]+)$/) | ||
var shorthand = repoUrl.match(/^([\w-_]+)\/([\w-_\.]+)#?([\w-_\.]+)?$/) | ||
var mediumhand = repoUrl.match(/^github:([\w-_]+)\/([\w-_\.]+)#?([\w-_\.]+)?$/) | ||
var antiquated = repoUrl.match(/^git@[\w-_\.]+:([\w-_]+)\/([\w-_\.]+)$/) | ||
@@ -34,8 +35,9 @@ if (shorthand) { | ||
// Turn git+http URLs into http URLs | ||
repo_url = repo_url.replace(/^git\+/, '') | ||
repoUrl = repoUrl.replace(/^git\+/, '') | ||
if (!isUrl(repo_url)) return null | ||
var parsedURL = url.parse(repo_url) | ||
if (!isUrl(repoUrl)) return null | ||
var parsedURL = url.parse(repoUrl) | ||
if (!parsedURL.hostname) return null | ||
if (parsedURL.hostname !== 'github.com' && !opts.enterprise) return null | ||
@@ -42,0 +44,0 @@ var parts = parsedURL.pathname.match(/^\/([\w-_]+)\/([\w-_\.]+)(\/tree\/[\w-_\.\/]+)?(\/blob\/[\w-_\.\/]+)?/) |
{ | ||
"name": "github-url-to-object", | ||
"version": "2.2.1", | ||
"version": "2.2.2", | ||
"description": "Extract user, repo, and other interesting properties from GitHub URLs", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "standard --format index.js && mocha", | ||
"test": "mocha && standard", | ||
"build": "browserify index.js --standalone gh > dist/gh.js", | ||
@@ -30,8 +30,12 @@ "deploy": "npm run build && git subtree push --prefix dist origin gh-pages && open https://zeke.github.io/github-url-to-object" | ||
"devDependencies": { | ||
"browserify": "^4.2.1", | ||
"harp": "^0.19.0", | ||
"mocha": "^1.19.0", | ||
"standard": "^3.7.0", | ||
"browserify": "^13.0.1", | ||
"mocha": "^2.5.3", | ||
"standard": "^7.1.2", | ||
"uglify-js": "^2.4.15" | ||
}, | ||
"standard": { | ||
"ignore": [ | ||
"dist" | ||
] | ||
} | ||
} |
@@ -76,2 +76,9 @@ # github-url-to-object [![Build Status](https://travis-ci.org/zeke/github-url-to-object.png?branch=master)](https://travis-ci.org/zeke/github-url-to-object) | ||
If you're using GitHub Enterprise, pass the `enterprise` option to allow | ||
your non-`github.com` URL to be parsed: | ||
```js | ||
gh('https://ghe.example.com:heroku/heroku-flags.git', {enterprise: true}) | ||
``` | ||
## Test | ||
@@ -78,0 +85,0 @@ |
@@ -27,8 +27,7 @@ /* globals before, describe, it */ | ||
}) | ||
}) | ||
describe("mediumhand", function(){ | ||
it("supports github:user/repo style", function(){ | ||
var obj = gh("github:user/repo#branch") | ||
describe('mediumhand', function () { | ||
it('supports github:user/repo style', function () { | ||
var obj = gh('github:user/repo#branch') | ||
assert.equal(obj.user, 'user') | ||
@@ -38,4 +37,4 @@ assert.equal(obj.repo, 'repo') | ||
it("supports github:user/repo#branch style", function(){ | ||
var obj = gh("github:user/repo#branch") | ||
it('supports github:user/repo#branch style', function () { | ||
var obj = gh('github:user/repo#branch') | ||
assert.equal(obj.user, 'user') | ||
@@ -57,3 +56,2 @@ assert.equal(obj.repo, 'repo') | ||
}) | ||
}) | ||
@@ -90,5 +88,5 @@ | ||
describe('github enterprise', function() { | ||
it("supports git@ URLs", function() { | ||
var obj = gh("git@ghe.example.com:heroku/heroku-flags.git") | ||
describe('github enterprise', function () { | ||
it('supports git@ URLs', function () { | ||
var obj = gh('git@ghe.example.com:heroku/heroku-flags.git', {enterprise: true}) | ||
assert.equal(obj.user, 'heroku') | ||
@@ -98,9 +96,8 @@ assert.equal(obj.repo, 'heroku-flags') | ||
it("supports git:// URLs", function() { | ||
var obj = gh("git://ghe.example.com/foo/bar.git") | ||
it('supports git:// URLs', function () { | ||
var obj = gh('git://ghe.example.com/foo/bar.git', {enterprise: true}) | ||
assert.equal(obj.user, 'foo') | ||
assert.equal(obj.repo, 'bar') | ||
}) | ||
}); | ||
}) | ||
}) | ||
@@ -158,5 +155,5 @@ | ||
describe('github enterprise', function() { | ||
it("supports http URLs", function() { | ||
var obj = gh("http://ghe.example.com/zeke/outlet.git") | ||
describe('github enterprise', function () { | ||
it('supports http URLs', function () { | ||
var obj = gh('http://ghe.example.com/zeke/outlet.git', {enterprise: true}) | ||
assert.equal(obj.user, 'zeke') | ||
@@ -166,8 +163,8 @@ assert.equal(obj.repo, 'outlet') | ||
it("supports https URLs", function() { | ||
var obj = gh("https://ghe.example.com/zeke/outlet.git") | ||
it('supports https URLs', function () { | ||
var obj = gh('https://ghe.example.com/zeke/outlet.git', {enterprise: true}) | ||
assert.equal(obj.user, 'zeke') | ||
assert.equal(obj.repo, 'outlet') | ||
}) | ||
}); | ||
}) | ||
}) | ||
@@ -178,33 +175,33 @@ | ||
describe('github.com', function() { | ||
before(function(){ | ||
obj = gh("zeke/ord") | ||
describe('github.com', function () { | ||
before(function () { | ||
obj = gh('zeke/ord') | ||
}) | ||
it("user", function() { | ||
assert.equal(obj.user, "zeke") | ||
it('user', function () { | ||
assert.equal(obj.user, 'zeke') | ||
}) | ||
it("repo", function() { | ||
assert.equal(obj.repo, "ord") | ||
it('repo', function () { | ||
assert.equal(obj.repo, 'ord') | ||
}) | ||
it("branch", function() { | ||
assert.equal(obj.branch, "master") | ||
it('branch', function () { | ||
assert.equal(obj.branch, 'master') | ||
}) | ||
it("tarball_url", function() { | ||
assert.equal(obj.tarball_url, "https://api.github.com/repos/zeke/ord/tarball/master") | ||
it('tarball_url', function () { | ||
assert.equal(obj.tarball_url, 'https://api.github.com/repos/zeke/ord/tarball/master') | ||
}) | ||
it("api_url", function() { | ||
assert.equal(obj.api_url, "https://api.github.com/repos/zeke/ord") | ||
it('api_url', function () { | ||
assert.equal(obj.api_url, 'https://api.github.com/repos/zeke/ord') | ||
}) | ||
it("https_url", function() { | ||
assert.equal(obj.https_url, "https://github.com/zeke/ord") | ||
it('https_url', function () { | ||
assert.equal(obj.https_url, 'https://github.com/zeke/ord') | ||
}) | ||
it("travis_url", function() { | ||
assert.equal(obj.travis_url, "https://travis-ci.org/zeke/ord") | ||
it('travis_url', function () { | ||
assert.equal(obj.travis_url, 'https://travis-ci.org/zeke/ord') | ||
}) | ||
@@ -217,29 +214,29 @@ | ||
describe('github enterprise', function() { | ||
before(function(){ | ||
obj = gh("https://ghe.example.com/zeke/outlet.git") | ||
describe('github enterprise', function () { | ||
before(function () { | ||
obj = gh('https://ghe.example.com/zeke/outlet.git', {enterprise: true}) | ||
}) | ||
it("user", function() { | ||
assert.equal(obj.user, "zeke") | ||
it('user', function () { | ||
assert.equal(obj.user, 'zeke') | ||
}) | ||
it("repo", function() { | ||
assert.equal(obj.repo, "outlet") | ||
it('repo', function () { | ||
assert.equal(obj.repo, 'outlet') | ||
}) | ||
it("branch", function() { | ||
assert.equal(obj.branch, "master") | ||
it('branch', function () { | ||
assert.equal(obj.branch, 'master') | ||
}) | ||
it("tarball_url", function() { | ||
assert.equal(obj.tarball_url, "https://ghe.example.com/api/v3/repos/zeke/outlet/tarball/master") | ||
it('tarball_url', function () { | ||
assert.equal(obj.tarball_url, 'https://ghe.example.com/api/v3/repos/zeke/outlet/tarball/master') | ||
}) | ||
it("api_url", function() { | ||
assert.equal(obj.api_url, "https://ghe.example.com/api/v3/repos/zeke/outlet") | ||
it('api_url', function () { | ||
assert.equal(obj.api_url, 'https://ghe.example.com/api/v3/repos/zeke/outlet') | ||
}) | ||
it("https_url", function() { | ||
assert.equal(obj.https_url, "https://ghe.example.com/zeke/outlet") | ||
it('https_url', function () { | ||
assert.equal(obj.https_url, 'https://ghe.example.com/zeke/outlet') | ||
}) | ||
@@ -283,3 +280,2 @@ | ||
}) | ||
}) | ||
@@ -294,4 +290,7 @@ | ||
}) | ||
it('returns null if hostname is not github.com', function () { | ||
assert.equal(gh('https://ghe.something.com/foo/bar'), null) | ||
}) | ||
}) | ||
}) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
82451
4
2218
95