Skip to content

Commit

Permalink
feat(ui): format clone url
Browse files Browse the repository at this point in the history
  • Loading branch information
aymanbagabas committed May 2, 2023
1 parent c5fa66a commit 106c049
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions ui/common/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package common

import (
"fmt"
"net/url"

"github.com/charmbracelet/soft-serve/server/utils"
"github.com/muesli/reflow/truncate"
)

Expand All @@ -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)
}

0 comments on commit 106c049

Please sign in to comment.