Skip to content

Commit fa3163c

Browse files
committed
handling git@ and https:git@ urls
1 parent e91d6a0 commit fa3163c

File tree

3 files changed

+39
-2
lines changed

3 files changed

+39
-2
lines changed

index.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,14 @@ module.exports = function (string) {
66
var m = /^([\w-]+)\/([\w-.]+)((?:#|@).+)?$/.exec(string)
77
if (m) return format(m)
88

9-
if (!~string.indexOf('://')) return false
9+
// normalize git@ and https:git@ urls
10+
string = string.replace(/^git@/, 'https://')
11+
string = string.replace(/^https:git@/, 'https://')
12+
string = string.replace('.com:', '.com/')
13+
14+
if (!~string.indexOf('://')) {
15+
return false
16+
}
1017
var url = parse(string)
1118

1219
switch (url.hostname) {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "parse-github-repo-url",
33
"description": "Parse a GitHub URL for user/project@version",
4-
"version": "1.0.0",
4+
"version": "1.1.0",
55
"author": {
66
"name": "Jonathan Ong",
77
"email": "[email protected]",

test.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,33 @@ describe('versioned', function () {
3737
})
3838
})
3939
})
40+
41+
describe('url parse', function () {
42+
var builtinUrlParse = require('url').parse
43+
44+
it('handles https:// url', function () {
45+
var url = 'https://foo.com/bar'
46+
var parsed = builtinUrlParse(url)
47+
assert.equal('foo.com', parsed.hostname)
48+
})
49+
50+
it('does not handle emails', function () {
51+
var url = '[email protected]/bar'
52+
var parsed = builtinUrlParse(url)
53+
assert.equal(null, parsed.hostname, JSON.stringify(parsed))
54+
})
55+
})
56+
57+
describe('git @ syntax', function () {
58+
it('works for git url', function () {
59+
var url = '[email protected]:bahmutov/lazy-ass.git'
60+
var parsed = parse(url)
61+
assert.deepEqual(['bahmutov', 'lazy-ass', ''], parsed)
62+
});
63+
64+
it('works for https:git url', function () {
65+
var url = 'https:[email protected]:bahmutov/lazy-ass.git'
66+
var parsed = parse(url)
67+
assert.deepEqual(['bahmutov', 'lazy-ass', ''], parsed)
68+
});
69+
})

0 commit comments

Comments
 (0)