diff --git a/ui/common/utils.go b/ui/common/utils.go index ae7c3839a..119f1b787 100644 --- a/ui/common/utils.go +++ b/ui/common/utils.go @@ -2,7 +2,9 @@ package common import ( "fmt" + "net/url" + "github.com/charmbracelet/soft-serve/server/utils" "github.com/muesli/reflow/truncate" ) @@ -16,5 +18,19 @@ func TruncateString(s string, max int) string { // RepoURL returns the URL of the repository. func RepoURL(publicURL, name string) string { + name = utils.SanitizeRepo(name) + ".git" + url, err := url.Parse(publicURL) + if err == nil { + switch url.Scheme { + case "ssh": + port := url.Port() + if port == "" || port == "22" { + return fmt.Sprintf("git clone git@%s:%s", url.Hostname(), name) + } else { + return fmt.Sprintf("git clone ssh://%s:%s/%s", url.Hostname(), url.Port(), name) + } + } + } + return fmt.Sprintf("git clone %s/%s", publicURL, name) }