1package common23import (4 "fmt"5 "net/url"67 "github.com/charmbracelet/soft-serve/pkg/utils"8 "github.com/muesli/reflow/truncate"9)1011// TruncateString is a convenient wrapper around truncate.TruncateString.12func TruncateString(s string, max int) string { //nolint:revive13 if max < 0 {14 max = 0 //nolint:revive15 }16 return truncate.StringWithTail(s, uint(max), "…") //nolint:gosec17}1819// RepoURL returns the URL of the repository.20func RepoURL(publicURL, name string) string {21 name = utils.SanitizeRepo(name) + ".git"22 url, err := url.Parse(publicURL)23 if err == nil {24 switch url.Scheme {25 case "ssh":26 port := url.Port()27 if port == "" || port == "22" {28 return fmt.Sprintf("git@%s:%s", url.Hostname(), name)29 }30 return fmt.Sprintf("ssh://%s:%s/%s", url.Hostname(), url.Port(), name)31 }32 }3334 return fmt.Sprintf("%s/%s", publicURL, name)35}