Skip to content

Commit 1912236

Browse files
committed
Merge branch 'fix-source-2parts-sld' of https://github.com/pvdlg/git-url-parse into new-version
2 parents 67ae07c + 13dae80 commit 1912236

File tree

3 files changed

+16
-17
lines changed

3 files changed

+16
-17
lines changed

lib/index.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
"use strict";
22

33
const gitUp = require("git-up");
4-
const parseDomain = require('parse-domain');
54

65
/**
76
* gitUrlParse
@@ -45,12 +44,14 @@ function gitUrlParse(url) {
4544
, splits = null
4645
;
4746

48-
urlInfo.toString = function (type) {
47+
urlInfo.toString = function (type) {
4948
return gitUrlParse.stringify(this, type);
5049
};
5150

52-
const parsedResource = parseDomain(urlInfo.resource);
53-
urlInfo.source = parsedResource ? parsedResource.domain + '.' + parsedResource.tld : urlInfo.resource;
51+
urlInfo.source = sourceParts.length > 2
52+
? sourceParts.slice(1 - sourceParts.length).join(".")
53+
: urlInfo.source = urlInfo.resource
54+
;
5455

5556
// Note: Some hosting services (e.g. Visual Studio Team Services) allow whitespace characters
5657
// in the repository and owner names so we decode the URL pieces to get the correct result
@@ -59,9 +60,10 @@ function gitUrlParse(url) {
5960
urlInfo.owner = decodeURIComponent(urlInfo.user);
6061

6162
switch (urlInfo.source) {
62-
case "cloudforge.com":
63+
case "git.cloudforge.com":
6364
urlInfo.owner = urlInfo.user;
6465
urlInfo.organization = sourceParts[0];
66+
urlInfo.source = "cloudforge.com";
6567
break;
6668
case "visualstudio.com":
6769
splits = urlInfo.name.split("/");

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@
2929
"test": "test"
3030
},
3131
"dependencies": {
32-
"git-up": "^2.0.0",
33-
"parse-domain": "^2.0.0"
32+
"git-up": "^2.0.0"
3433
},
3534
"devDependencies": {
3635
"browserify": "^13.0.1",

test/index.js

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,14 @@ tester.describe("parse urls", test => {
171171
test.expect(res.toString()).toBe("https://companyname.visualstudio.com/DefaultCollection/MyProject/_git/MyRepo");
172172
});
173173

174+
// custom git hosted URL with 2 parts SLD
175+
test.should("parse Gih hosted urls with two parts SLD", () => {
176+
var res = gitUrlParse("https://domain.git.com.cn/owner/name.git");
177+
test.expect(res.source).toBe("git.com.cn");
178+
test.expect(res.owner).toBe("owner");
179+
test.expect(res.name).toBe("name");
180+
});
181+
174182
// Handle URL encoded names of owners and repositories
175183
test.should("https URLs with URL encoded characters", () => {
176184
var res = gitUrlParse("https://companyname.visualstudio.com/My%20Project/_git/My%20Repo");
@@ -291,14 +299,4 @@ tester.describe("parse urls", test => {
291299
res.user = "user";
292300
test.expect(res.toString()).toBe("http://user@github.com/owner/name.git");
293301
});
294-
295-
test.it("custom url", () => {
296-
var res = gitUrlParse("https://git.test.com.cn/a/b");
297-
test.expect(res.source).toBe('test.com.cn');
298-
})
299-
300-
test.it("local urls", () => {
301-
var res = gitUrlParse("http://machine:8080/tfs/Collection/Project.Name/_git/repository");
302-
test.expect(res.source).toBe('machine');
303-
})
304302
});

0 commit comments

Comments
 (0)