Skip to content

Commit

Permalink
Format ssh url when domain has scheme
Browse files Browse the repository at this point in the history
  • Loading branch information
dinosk committed Sep 24, 2020
1 parent 3d69070 commit a1b3593
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 2 additions & 0 deletions gitlab/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())

Expand Down
7 changes: 6 additions & 1 deletion gitprovider/repositoryref.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
}
Expand Down

0 comments on commit a1b3593

Please sign in to comment.