Skip to content

Commit 62d17d0

Browse files
committed
commit url support
1 parent c66bd99 commit 62d17d0

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

lib/index.js

+5
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,17 @@ function gitUrlParse(url) {
9494
if (splits.length >= 2) {
9595
const blobIndex = splits.indexOf("blob", 2);
9696
const treeIndex = splits.indexOf("tree", 2);
97+
const commitIndex = splits.indexOf("commit", 2);
9798
nameIndex = blobIndex > 0 ? blobIndex - 1
9899
: treeIndex > 0 ? treeIndex - 1
100+
: commitIndex > 0 ? commitIndex - 1
99101
: nameIndex;
100102

101103
urlInfo.owner = splits.slice(0, nameIndex).join('/');
102104
urlInfo.name = splits[nameIndex];
105+
if (commitIndex) {
106+
urlInfo.commit = splits[nameIndex + 2]
107+
}
103108
}
104109

105110
urlInfo.ref = "";

test/index.js

+8
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const URLS = {
1212
, gitSsh: "git+ssh://[email protected]/IonicaBizau/git-url-parse"
1313
, ref: "https://github.com/IonicaBizau/git-url-parse/blob/master/test/index.js"
1414
, shorthand: "IonicaBizau/git-url-parse"
15+
, commit: "https://github.com/IonicaBizau/git-url-parse/commit/9c6443245ace92d237b7b274d4606a616e071c4e"
1516
};
1617

1718
tester.describe("parse urls", test => {
@@ -299,4 +300,11 @@ tester.describe("parse urls", test => {
299300
res.user = "user";
300301
test.expect(res.toString()).toBe("http://[email protected]/owner/name.git");
301302
});
303+
304+
// commits
305+
test.should("parse commit urls", () => {
306+
var res = gitUrlParse(URLS.commit);
307+
test.expect(res.name).toBe("git-url-parse");
308+
test.expect(res.commit).toBe("9c6443245ace92d237b7b274d4606a616e071c4e");
309+
});
302310
});

0 commit comments

Comments
 (0)