Skip to content

Commit

Permalink
Merge branch 'fix-name-organization-on-issueURL' of github.com:msivas…
Browse files Browse the repository at this point in the history
…ubramaniaan/git-url-parse into new-version
  • Loading branch information
IonicaBizau committed Jan 2, 2024
2 parents 4c01a68 + 2c26c51 commit e810584
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
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 @@ -514,4 +515,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");
});
});

0 comments on commit e810584

Please sign in to comment.