2014-11-24 23:10:37 +00:00
|
|
|
package urlutil
|
|
|
|
|
2015-04-24 22:12:45 +00:00
|
|
|
import (
|
|
|
|
"regexp"
|
|
|
|
"strings"
|
|
|
|
)
|
2014-11-24 23:10:37 +00:00
|
|
|
|
|
|
|
var (
|
|
|
|
validPrefixes = []string{
|
|
|
|
"git://",
|
|
|
|
"github.com/",
|
|
|
|
"git@",
|
|
|
|
}
|
2015-04-24 22:12:45 +00:00
|
|
|
|
|
|
|
urlPathWithFragmentSuffix = regexp.MustCompile(".git(?:#.+)?$")
|
2014-11-24 23:10:37 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// IsGitURL returns true if the provided str is a git repository URL.
|
|
|
|
func IsGitURL(str string) bool {
|
2015-04-24 22:12:45 +00:00
|
|
|
if IsURL(str) && urlPathWithFragmentSuffix.MatchString(str) {
|
2014-11-24 23:10:37 +00:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
for _, prefix := range validPrefixes {
|
|
|
|
if strings.HasPrefix(str, prefix) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
// IsGitTransport returns true if the provided str is a git transport by inspecting
|
|
|
|
// the prefix of the string for known protocols used in git.
|
|
|
|
func IsGitTransport(str string) bool {
|
|
|
|
return IsURL(str) || strings.HasPrefix(str, "git://") || strings.HasPrefix(str, "git@")
|
|
|
|
}
|