Skip to content

Commit

Permalink
fix: add support for GitLab dotted user
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastien-prudhomme committed Feb 2, 2017
1 parent 9394956 commit a3c2558
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
8 changes: 4 additions & 4 deletions index.js
Expand Up @@ -2,7 +2,7 @@ var parse = require('url').parse

module.exports = function (string) {
// user/repo#version
var m = /^([\w-]+)\/([\w-.]+)((?:#|@).+)?$/.exec(string)
var m = /^([\w-.]+)\/([\w-.]+)((?:#|@).+)?$/.exec(string)
if (m) return format(m)

string = string.replace('//www.', '//')
Expand All @@ -19,17 +19,17 @@ module.exports = function (string) {
var path = url.pathname.replace(/\.git$/, '')

// https://www.npmjs.org/doc/json.html#Git-URLs-as-Dependencies
var m = /^\/([\w-]+)\/([\w-.]+)$/.exec(path)
var m = /^\/([\w-.]+)\/([\w-.]+)$/.exec(path)
if (m) return m.slice(1, 3).concat((url.hash || '').slice(1))

// archive link
// https://developer.github.com/v3/repos/contents/#get-archive-link
var m = /^\/repos\/([\w-]+)\/([\w-.]+)\/(?:tarball|zipball)(\/.+)?$/.exec(path)
var m = /^\/repos\/([\w-.]+)\/([\w-.]+)\/(?:tarball|zipball)(\/.+)?$/.exec(path)
if (m) return format(m)

// codeload link
// https://developer.github.com/v3/repos/contents/#response-4
var m = /^\/([\w-]+)\/([\w-.]+)\/(?:legacy\.(?:zip|tar\.gz))(\/.+)?$/.exec(path)
var m = /^\/([\w-.]+)\/([\w-.]+)\/(?:legacy\.(?:zip|tar\.gz))(\/.+)?$/.exec(path)
if (m) return format(m)

// tarball link
Expand Down
13 changes: 13 additions & 0 deletions test.js
Expand Up @@ -50,6 +50,19 @@ describe('versioned', function () {
})
})

describe('dotted user', function () {
[
'my.component/my.emitter',
'https://github.com/my.component/my.emitter',
'https://github.com/repos/my.component/my.emitter/tarball',
'https://codeload.github.com/my.component/my.emitter/legacy.zip',
].forEach(function (url) {
it(url, function () {
assert.deepEqual(['my.component', 'my.emitter', ''], parse(url))
})
})
})

describe('url parse', function () {
var builtinUrlParse = require('url').parse

Expand Down

0 comments on commit a3c2558

Please sign in to comment.