mirror of https://github.com/curusarn/resh
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
721 B
31 lines
721 B
package normalize
|
|
|
|
import (
|
|
"net/url"
|
|
"strings"
|
|
|
|
giturls "github.com/whilp/git-urls"
|
|
"go.uber.org/zap"
|
|
)
|
|
|
|
// GitRemote helper
|
|
// Returns normalized git remote - valid even on error
|
|
func GitRemote(sugar *zap.SugaredLogger, gitRemote string) string {
|
|
if len(gitRemote) == 0 {
|
|
return ""
|
|
}
|
|
gitRemote = strings.TrimSuffix(gitRemote, ".git")
|
|
parsedURL, err := giturls.Parse(gitRemote)
|
|
if err != nil {
|
|
sugar.Errorw("Failed to parse git remote", zap.Error(err),
|
|
"gitRemote", gitRemote,
|
|
)
|
|
return gitRemote
|
|
}
|
|
if parsedURL.User == nil || parsedURL.User.Username() == "" {
|
|
parsedURL.User = url.User("git")
|
|
}
|
|
// TODO: figure out what scheme we want
|
|
parsedURL.Scheme = "git+ssh"
|
|
return parsedURL.String()
|
|
}
|
|
|