-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
66 lines (56 loc) · 1.28 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/**
* Module dependencies.
*/
var debug = require('debug')('duo-parse');
/**
* Export `parse`
*/
module.exports = parse;
/**
* Parse the given `slug`.
*
* @param {String} slug
* @return {Object}
* @api public
*/
function parse(slug) {
var obj = { slug: slug };
var at, colon, parts;
if (~(at = slug.indexOf('@'))) {
var split = slug.substring(at + 1);
parts = slug.substring(0, at).split('/');
if (~(colon = split.indexOf(':'))) {
// user/repo@version:path
obj.ref = split.substring(0, colon);
obj.path = split.substring(colon + 1);
} else {
// user/repo@version
obj.ref = split;
}
} else {
if (~(colon = slug.indexOf(':'))) {
// user/repo:path
obj.path = slug.substring(colon + 1);
parts = slug.substring(0, colon).split('/');
} else {
// user/repo
parts = slug.split('/');
}
}
if (parts.length === 3) {
// provider.com/someuser/somerepo
obj.provider = parts[0];
obj.user = parts[1];
obj.repo = parts[2];
} else if (parts.length === 2) {
// someuser/somerepo
obj.user = parts[0];
obj.repo = parts[1];
} else {
// somerepo
obj.repo = parts[0];
}
obj.provider = obj.provider || 'github.com';
debug('parsed %s', slug, obj);
return obj;
}