Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle blob and tree being in owner and project name #14

Merged
merged 1 commit into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
9 changes: 9 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ describe('parse-github-url', function() {
assert.equal(gh('https://raw.githubusercontent.com/assemble/verb/4d0ebde055557a0d1d988c01e0f070df8cc8fa07').branch, '4d0ebde055557a0d1d988c01e0f070df8cc8fa07');
assert.equal(gh('https://raw.githubusercontent.com/assemble/verb/4d0ebde055557a0d1d988c01e0f070df8cc8fa07/README.md').branch, '4d0ebde055557a0d1d988c01e0f070df8cc8fa07');
assert.equal(gh('https://raw.githubusercontent.com/assemble/verb/dev/README.md').branch, 'dev');
assert.equal(gh('https://github.com/contentful/extensions/blob/master/samples/content-tree/extension.json').branch, 'master');
});

it('should get the filepath:', function() {
Expand All @@ -78,6 +79,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