Skip to content

Commit

Permalink
Handle blob and tree being in owner and project name
Browse files Browse the repository at this point in the history
  • Loading branch information
Glavin001 committed Aug 29, 2018
1 parent eb7f2be commit c91e48b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
5 changes: 3 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,13 @@ function parse(str) {
}

var blob = str.indexOf('blob');
if (blob !== -1) {
if (hasBlob && blob !== -1) {
obj.blob = str.slice(blob + 5);
}

var hasTree = seg[2] === 'tree';
var tree = str.indexOf('tree');
if (tree !== -1) {
if (hasTree && tree !== -1) {
var idx = tree + 5;
var branch = str.slice(idx);
var slash = branch.indexOf('/');
Expand Down
8 changes: 8 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,14 @@ describe('parse-github-url', function() {
assert.equal(gh('https://github.com/assemble/verb/tree/dev').filepath, null);
assert.equal(gh('https://raw.githubusercontent.com/assemble/verb/dev/README.md').filepath, 'README.md');
assert.equal(gh('https://raw.githubusercontent.com/assemble/verb/dev/bar/README.md').filepath, 'bar/README.md');
assert.equal(gh('https://github.com/owner/blob/blob/foo/README.md').filepath, 'README.md');
assert.equal(gh('https://github.com/blob/project/blob/foo/README.md').filepath, 'README.md');
assert.equal(gh('https://github.com/owner/tree/tree/foo/README.md').filepath, null);
assert.equal(gh('https://github.com/tree/project/tree/foo/README.md').filepath, null);
assert.equal(gh('https://raw.githubusercontent.com/owner/tree/dev/README.md').filepath, 'README.md');
assert.equal(gh('https://raw.githubusercontent.com/tree/project/dev/README.md').filepath, 'README.md');
assert.equal(gh('https://raw.githubusercontent.com/owner/blob/dev/README.md').filepath, 'README.md');
assert.equal(gh('https://raw.githubusercontent.com/blob/project/dev/README.md').filepath, 'README.md');
});

it('should use master branch when another branch is not defined:', function() {
Expand Down

0 comments on commit c91e48b

Please sign in to comment.