From af15e17cedcad7c8f9469de00977ffe47f246009 Mon Sep 17 00:00:00 2001 From: Alan Crosswell Date: Sun, 24 Jan 2021 11:35:42 -0500 Subject: [PATCH] add Azure DevOps parsing of git branch --- lib/index.js | 3 +++ test/index.js | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/lib/index.js b/lib/index.js index 36d3ef8..651f1db 100644 --- a/lib/index.js +++ b/lib/index.js @@ -138,6 +138,9 @@ function gitUrlParse(url) { if(urlInfo.query && urlInfo.query['path']) { urlInfo.filepath = urlInfo.query['path'].replace(/^\/+/g, ''); // Strip leading slash (/) } + if(urlInfo.query && urlInfo.query['version']) { // version=GB + urlInfo.ref = urlInfo.query['version'].replace(/^GB/, ''); // remove GB + } break; } default: diff --git a/test/index.js b/test/index.js index 6d09848..d293ed7 100644 --- a/test/index.js +++ b/test/index.js @@ -277,6 +277,25 @@ tester.describe("parse urls", test => { test.expect(res.filepath).toBe("test/index.js"); }); + // https Azure DevOps (formerly Visual Studio Team Services) + test.should("parse Azure DevOps HTTPS urls with branch", () => { + // Parse URL for matching project and repo names + var res = gitUrlParse("https://dev.azure.com/MyOrganization/MatchedName/MyTeam/_git/MatchedName?path=%2Ftest%2Findex.js&version=GBother"); + test.expect(res.source).toBe("azure.com"); + test.expect(res.owner).toBe("MatchedName"); + test.expect(res.name).toBe("MatchedName"); + test.expect(res.filepath).toBe("test/index.js"); + test.expect(res.ref).toBe("other"); + + // Parse URL for non-matching project and repo names with branch + res = gitUrlParse("https://dev.azure.com/MyOrganization/MyProject/_git/MyRepo?path=%2Ftest%2Findex.js&version=GBother"); + test.expect(res.source).toBe("azure.com"); + test.expect(res.owner).toBe("MyProject"); + test.expect(res.name).toBe("MyRepo"); + test.expect(res.filepath).toBe("test/index.js"); + test.expect(res.ref).toBe("other"); + }); + // ssh Azure DevOps (formerly Visual Studio Team Services) test.should("parse Azure DevOps SSH urls", () => { // Parse URL for matching project and repo names