Skip to content

Commit

Permalink
fix(ui): empty repo clone command
Browse files Browse the repository at this point in the history
  • Loading branch information
aymanbagabas committed May 2, 2023
1 parent e00b19d commit 0b842d7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
15 changes: 10 additions & 5 deletions ui/common/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,26 @@ func TruncateString(s string, max int) string {
return truncate.StringWithTail(s, uint(max), "…")
}

// CloneCmd returns the URL of the repository.
func CloneCmd(publicURL, name string) 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)
return fmt.Sprintf("git@%s:%s", url.Hostname(), name)
} else {
return fmt.Sprintf("git clone ssh://%s:%s/%s", url.Hostname(), url.Port(), name)
return fmt.Sprintf("ssh://%s:%s/%s", url.Hostname(), url.Port(), name)
}
}
}

return fmt.Sprintf("git clone %s/%s", publicURL, name)
return fmt.Sprintf("%s/%s", publicURL, name)
}

// CloneCmd returns the URL of the repository.
func CloneCmd(publicURL, name string) string {
return fmt.Sprintf("git clone %s", RepoURL(publicURL, name))
}
2 changes: 1 addition & 1 deletion ui/pages/repo/empty.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@ git push -u origin main
git remote add origin %[1]s
git push -u origin main
`+"```"+`
`, common.CloneCmd(cfg.SSH.PublicURL, repo))
`, common.RepoURL(cfg.SSH.PublicURL, repo))
}

0 comments on commit 0b842d7

Please sign in to comment.