From a1b35939a7ffd4c40498bd8c8570cf8d427f3f2c Mon Sep 17 00:00:00 2001 From: Dinos Kousidis Date: Thu, 24 Sep 2020 14:14:09 +0200 Subject: [PATCH] Format ssh url when domain has scheme --- gitlab/integration_test.go | 2 ++ gitprovider/repositoryref.go | 7 ++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/gitlab/integration_test.go b/gitlab/integration_test.go index 887352ca..8da9979f 100644 --- a/gitlab/integration_test.go +++ b/gitlab/integration_test.go @@ -234,6 +234,8 @@ var _ = Describe("GitLab Provider", func() { // We know that a repo with this name doesn't exist in the organization, let's verify we get an // ErrNotFound repoRef := newOrgRepoRef(testOrgName, testOrgRepoName) + sshURL := repoRef.GetCloneURL(gitprovider.TransportTypeSSH) + Expect(sshURL).NotTo(Equal("")) _, err = c.OrgRepositories().Get(ctx, repoRef) Expect(errors.Is(err, gitprovider.ErrNotFound)).To(BeTrue()) diff --git a/gitprovider/repositoryref.go b/gitprovider/repositoryref.go index ee2745b3..1f8d249f 100644 --- a/gitprovider/repositoryref.go +++ b/gitprovider/repositoryref.go @@ -254,7 +254,12 @@ func GetCloneURL(rs RepositoryRef, transport TransportType) string { case TransportTypeGit: return fmt.Sprintf("git@%s:%s/%s.git", rs.GetDomain(), rs.GetIdentity(), rs.GetRepository()) case TransportTypeSSH: - return fmt.Sprintf("ssh://git@%s/%s/%s", rs.GetDomain(), rs.GetIdentity(), rs.GetRepository()) + parsedDomain, _ := url.Parse(rs.GetDomain()) + domain := parsedDomain.Host + if parsedDomain.Port() != "" { + domain = domain + ":" + parsedDomain.Port() + } + return fmt.Sprintf("ssh://git@%s/%s/%s", domain, rs.GetIdentity(), rs.GetRepository()) } return "" }