106c049f3de617c210541fe4b1e8dbd802f01d84

Author
Ayman Bagabas <ayman.bagabas@gmail.com>
Committer
Ayman Bagabas <ayman.bagabas@gmail.com>
Date

Message

feat(ui): format clone url

Diff

 1diff --git a/ui/common/utils.go b/ui/common/utils.go
 2index ae7c3839a6197e3245b96a5d703fd94594005f85..119f1b787d953586d9723a4a38a8f39859015f0f 100644
 3--- a/ui/common/utils.go
 4+++ b/ui/common/utils.go
 5@@ -2,7 +2,9 @@ package common
 6 
 7 import (
 8 	"fmt"
 9+	"net/url"
10 
11+	"github.com/charmbracelet/soft-serve/server/utils"
12 	"github.com/muesli/reflow/truncate"
13 )
14 
15@@ -16,5 +18,19 @@ func TruncateString(s string, max int) string {
16 
17 // RepoURL returns the URL of the repository.
18 func RepoURL(publicURL, name string) string {
19+	name = utils.SanitizeRepo(name) + ".git"
20+	url, err := url.Parse(publicURL)
21+	if err == nil {
22+		switch url.Scheme {
23+		case "ssh":
24+			port := url.Port()
25+			if port == "" || port == "22" {
26+				return fmt.Sprintf("git clone git@%s:%s", url.Hostname(), name)
27+			} else {
28+				return fmt.Sprintf("git clone ssh://%s:%s/%s", url.Hostname(), url.Port(), name)
29+			}
30+		}
31+	}
32+
33 	return fmt.Sprintf("git clone %s/%s", publicURL, name)
34 }