Skip to content

fixed name and organization issue when parsing on the issue URL #159

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

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
4 changes: 3 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,13 @@ function gitUrlParse(url) {
const blobIndex = splits.indexOf("blob", 2);
const treeIndex = splits.indexOf("tree", 2);
const commitIndex = splits.indexOf("commit", 2);
const issuesIndex = splits.indexOf("issues", 2);
const srcIndex = splits.indexOf("src", 2);
const rawIndex = splits.indexOf("raw", 2);
const editIndex = splits.indexOf("edit", 2);
nameIndex = dashIndex > 0 ? dashIndex - 1
: blobIndex > 0 ? blobIndex - 1
: issuesIndex > 0 ? issuesIndex - 1
: treeIndex > 0 ? treeIndex - 1
: commitIndex > 0 ? commitIndex - 1
: srcIndex > 0 ? srcIndex - 1
Expand All @@ -171,7 +173,7 @@ function gitUrlParse(url) {

urlInfo.owner = splits.slice(0, nameIndex).join('/');
urlInfo.name = splits[nameIndex];
if (commitIndex) {
if (commitIndex && issuesIndex < 0) {
urlInfo.commit = splits[nameIndex + 2]
}
}
Expand Down
7 changes: 7 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const URLS = {
, ref: "https://github.com/42IonicaBizau/git-url-parse/blob/master/test/index.js"
, shorthand: "42IonicaBizau/git-url-parse"
, commit: "https://github.com/42IonicaBizau/git-url-parse/commit/9c6443245ace92d237b7b274d4606a616e071c4e"
, issue: "https://github.com/IonicaBizau/git-url-parse/issues/133"
};

const gitUser = (url) => url.replace('custom-user@', 'git@');
Expand Down Expand Up @@ -510,4 +511,10 @@ tester.describe("parse urls", test => {
test.expect(res.name).toBe("git-url-parse");
test.expect(res.commit).toBe("9c6443245ace92d237b7b274d4606a616e071c4e");
});

test.should("parse issues urls", () => {
var res = gitUrlParse(URLS.issue);
test.expect(res.name).toBe("git-url-parse");
test.expect(res.organization).toBe("IonicaBizau");
});
});