From 94be867a54b4872920a5005671205e7a4263e17f Mon Sep 17 00:00:00 2001 From: Florian Assmus Date: Fri, 11 Jan 2019 13:41:29 +0100 Subject: [PATCH 1/2] Remove git:: prefix for all urls not only GitLab --- pkg/loader/gitcloner.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/pkg/loader/gitcloner.go b/pkg/loader/gitcloner.go index 01d21d4cd8..7701f68a72 100644 --- a/pkg/loader/gitcloner.go +++ b/pkg/loader/gitcloner.go @@ -187,10 +187,8 @@ func normalizeGitHostSpec(host string) string { host = "https://github.com/" } } - if strings.Contains(s, "gitlab") { - if strings.HasPrefix(s, "git::") { - host = strings.TrimLeft(s, "git::") - } + if strings.HasPrefix(s, "git::") { + host = strings.TrimLeft(s, "git::") } return host } From 176ad74a1cfc24b5d8dd84d659812237d775c599 Mon Sep 17 00:00:00 2001 From: Florian Assmus Date: Tue, 15 Jan 2019 22:53:36 +0100 Subject: [PATCH 2/2] Add unit test for additional git url patterns --- pkg/loader/gitcloner.go | 19 +++++++++++-------- pkg/loader/gitcloner_test.go | 29 ++++++++++++++++++++++------- 2 files changed, 33 insertions(+), 15 deletions(-) diff --git a/pkg/loader/gitcloner.go b/pkg/loader/gitcloner.go index 7701f68a72..56adc5770f 100644 --- a/pkg/loader/gitcloner.go +++ b/pkg/loader/gitcloner.go @@ -43,6 +43,7 @@ func isRepoUrl(arg string) bool { return !filepath.IsAbs(arg) && (strings.HasPrefix(arg, "git::") || strings.HasPrefix(arg, "gh:") || + strings.HasPrefix(arg, "ssh:") || strings.HasPrefix(arg, "github.com") || strings.HasPrefix(arg, "git@") || strings.Index(arg, "github.com/") > -1 || @@ -159,20 +160,22 @@ func parseHostSpec(n string) (string, string) { for _, p := range []string{ // Order matters here. "git::", "gh:", "ssh://", "https://", "http://", - "git@", "github.com:", "github.com/", "gitlab.com/"} { + "git@", "github.com:", "github.com/"} { if strings.ToLower(n[:len(p)]) == p { n = n[len(p):] host = host + p } } + + // If host is a http(s) or ssh URL, grab the domain part. for _, p := range []string{ - "git-codecommit.[a-z0-9-]*.amazonaws.com/", - "dev.azure.com/", - ".*visualstudio.com/"} { - index := regexp.MustCompile(p).FindStringIndex(n) - if len(index) > 0 { - host = host + n[0:index[len(index)-1]] - n = n[index[len(index)-1]:] + "ssh://", "https://", "http://"} { + if strings.HasSuffix(strings.ToLower(host), p) { + index := regexp.MustCompile("^(.*?)/").FindStringIndex(n) + if len(index) > 0 { + host = host + n[0:index[len(index)-1]] + n = n[index[len(index)-1]:] + } } } return host, n diff --git a/pkg/loader/gitcloner_test.go b/pkg/loader/gitcloner_test.go index 672cf16a83..4b0b1f386e 100644 --- a/pkg/loader/gitcloner_test.go +++ b/pkg/loader/gitcloner_test.go @@ -60,6 +60,18 @@ func TestIsRepoURL(t *testing.T) { input: "git@bitbucket.org:org/repo.git", expected: true, }, + { + input: "git::http://git.example.com/org/repo.git", + expected: true, + }, + { + input: "git::https://git.example.com/org/repo.git", + expected: true, + }, + { + input: "ssh://git.example.com:7999/org/repo.git", + expected: true, + }, { input: "/github.com/org/repo", expected: false, @@ -194,13 +206,16 @@ var paths = []string{"README.md", "foo/krusty.txt", ""} var hrefArgs = []string{"someBranch", ""} var extractFmts = map[string]string{ - "gh:%s": "gh:", - "GH:%s": "gh:", - "gitHub.com/%s": "https://github.com/", - "https://github.com/%s": "https://github.com/", - "hTTps://github.com/%s": "https://github.com/", - "git::https://gitlab.com/%s": "https://gitlab.com/", - "github.com:%s": "https://github.com/", + "gh:%s": "gh:", + "GH:%s": "gh:", + "gitHub.com/%s": "https://github.com/", + "https://github.com/%s": "https://github.com/", + "hTTps://github.com/%s": "https://github.com/", + "git::https://gitlab.com/%s": "https://gitlab.com/", + "github.com:%s": "https://github.com/", + "git::http://git.example.com/%s": "http://git.example.com/", + "git::https://git.example.com/%s": "https://git.example.com/", + "ssh://git.example.com:7999/%s": "ssh://git.example.com:7999/", } func TestParseGithubUrl(t *testing.T) {