Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ssh clone url when ssh domain has port #182

Merged
merged 1 commit into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion common/utils/common/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,10 @@ func buildHTTPCloneURL(domain string, repoType types.RepositoryType, path string

func buildSSHCloneURL(domain string, repoType types.RepositoryType, path string) string {
sshDomainWithoutPrefix := strings.TrimPrefix(domain, "ssh://")
return fmt.Sprintf("%s:%ss/%s.git", strings.TrimSuffix(sshDomainWithoutPrefix, "/"), repoType, path)
hasPort := strings.Contains(sshDomainWithoutPrefix, ":")
pulltheflower marked this conversation as resolved.
Show resolved Hide resolved
if hasPort {
pulltheflower marked this conversation as resolved.
Show resolved Hide resolved
return fmt.Sprintf("ssh://%s/%ss/%s.git", strings.TrimSuffix(sshDomainWithoutPrefix, "/"), repoType, path)
} else {
return fmt.Sprintf("%s:%ss/%s.git", strings.TrimSuffix(sshDomainWithoutPrefix, "/"), repoType, path)
}
}
24 changes: 24 additions & 0 deletions common/utils/common/repo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,30 @@ func TestBuildCloneInfo(t *testing.T) {
SSHCloneURL: "git@opencsg.com:models/abc/def.git",
},
},
{
name: "Test BuildCloneInfo when SSHDomain without ssh:// prefix and port",
args: args{
config: &config.Config{
APIServer: struct {
Port int `env:"STARHUB_SERVER_SERVER_PORT, default=8080"`
PublicDomain string `env:"STARHUB_SERVER_PUBLIC_DOMAIN, default=http://localhost:8080"`
SSHDomain string `env:"STARHUB_SERVER_SSH_DOMAIN, default=git@localhost:2222"`
}{
Port: 8080,
PublicDomain: "https://opencsg.com",
SSHDomain: "ssh://git@opencsg.com:2222",
pulltheflower marked this conversation as resolved.
Show resolved Hide resolved
},
},
repository: &database.Repository{
RepositoryType: types.ModelRepo,
Path: "abc/def",
},
},
want: types.Repository{
HTTPCloneURL: "https://opencsg.com/models/abc/def.git",
SSHCloneURL: "ssh://git@opencsg.com:2222/models/abc/def.git",
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down