feat(ui): format clone url

Ayman Bagabas created

Change summary

ui/common/utils.go | 16 ++++++++++++++++
1 file changed, 16 insertions(+)

Detailed changes

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)
 }