Skip to content

Commit

Permalink
Merge pull request #690 from fassmus/CloneBaseFromPrivateGit
Browse files Browse the repository at this point in the history
Remove git:: prefix for all git URLs not only GitLab
  • Loading branch information
k8s-ci-robot authored Jan 16, 2019
2 parents 549290c + 176ad74 commit 0be9815
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 19 deletions.
25 changes: 13 additions & 12 deletions pkg/loader/gitcloner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 ||
Expand Down Expand Up @@ -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
Expand All @@ -187,10 +190,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
}
Expand Down
29 changes: 22 additions & 7 deletions pkg/loader/gitcloner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,18 @@ func TestIsRepoURL(t *testing.T) {
input: "[email protected]: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,
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 0be9815

Please sign in to comment.