From 2c26c51c5e732f3c993c1db6203ac1e4a34844db Mon Sep 17 00:00:00 2001 From: msivasubramaniaan Date: Thu, 22 Jun 2023 21:51:29 +0530 Subject: [PATCH] fixed name and organization issue when parsing on the issue url Signed-off-by: msivasubramaniaan --- lib/index.js | 4 +++- test/index.js | 7 +++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/index.js b/lib/index.js index 016c0ee..9075e99 100644 --- a/lib/index.js +++ b/lib/index.js @@ -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 @@ -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] } } diff --git a/test/index.js b/test/index.js index f9bc87d..dd2029d 100644 --- a/test/index.js +++ b/test/index.js @@ -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@'); @@ -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"); + }); });