File tree Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -39,6 +39,10 @@ function parse(str) {
39
39
var hasBlob = seg [ 2 ] === 'blob' ;
40
40
if ( hasBlob && ! isChecksum ( seg [ 3 ] ) ) {
41
41
obj . branch = seg [ 3 ] ;
42
+ if ( seg . length > 4 )
43
+ {
44
+ obj . filepath = seg . slice ( 4 ) . join ( '/' ) ;
45
+ }
42
46
}
43
47
44
48
var blob = str . indexOf ( 'blob' ) ;
@@ -80,14 +84,20 @@ function parse(str) {
80
84
}
81
85
}
82
86
83
- obj . branch = obj . branch || seg [ 2 ] || getBranch ( obj . path , obj ) ;
87
+ if ( ! obj . branch ) {
88
+ obj . branch = seg [ 2 ] || getBranch ( obj . path , obj ) ;
89
+ if ( seg . length > 3 ) {
90
+ obj . filepath = seg . slice ( 3 ) . join ( '/' ) ;
91
+ }
92
+ }
84
93
var res = { } ;
85
94
res . host = obj . host || 'github.com' ;
86
95
res . owner = obj . owner || null ;
87
96
res . name = obj . name || null ;
88
97
res . repo = obj . repo ;
89
98
res . repository = res . repo ;
90
99
res . branch = obj . branch ;
100
+ res . filepath = obj . filepath || null ;
91
101
return res ;
92
102
}
93
103
Original file line number Diff line number Diff line change @@ -68,6 +68,18 @@ describe('parse-github-url', function() {
68
68
assert . equal ( gh ( 'https://raw.githubusercontent.com/assemble/verb/dev/README.md' ) . branch , 'dev' ) ;
69
69
} ) ;
70
70
71
+ it ( 'should get the filepath:' , function ( ) {
72
+ assert . equal ( gh ( 'assemble/verb#branch' ) . filepath , null ) ;
73
+ assert . equal ( gh ( '[email protected] :assemble/verb.git#0.6.0' ) . filepath , null ) ;
74
+ assert . equal ( gh ( 'https://github.com/assemble/verb/blob/foo/README.md' ) . filepath , 'README.md' ) ;
75
+ assert . equal ( gh ( 'https://github.com/assemble/verb/blob/foo/' ) . filepath , null ) ;
76
+ assert . equal ( gh ( 'https://github.com/assemble/verb/blob/foo' ) . filepath , null ) ;
77
+ assert . equal ( gh ( 'https://github.com/assemble/verb/blob/foo/bar/README.md' ) . filepath , 'bar/README.md' ) ;
78
+ assert . equal ( gh ( 'https://github.com/assemble/verb/tree/dev' ) . filepath , null ) ;
79
+ assert . equal ( gh ( 'https://raw.githubusercontent.com/assemble/verb/dev/README.md' ) . filepath , 'README.md' ) ;
80
+ assert . equal ( gh ( 'https://raw.githubusercontent.com/assemble/verb/dev/bar/README.md' ) . filepath , 'bar/README.md' ) ;
81
+ } ) ;
82
+
71
83
it ( 'should use master branch when another branch is not defined:' , function ( ) {
72
84
assert . equal ( gh ( 'assemble/verb' ) . branch , 'master' ) ;
73
85
assert . equal ( gh ( 'git://github.com/foo/bar.git' ) . branch , 'master' ) ;
You can’t perform that action at this time.
0 commit comments