Blog/utils/git.go

20 lines
373 B
Go
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package utils
import (
"errors"
"strings"
)
//通过git url 返回仓库的名字
func GetRepoName(gitUrl string) (string, error) {
if !strings.HasSuffix(gitUrl, ".git") {
return "", errors.New("git URL must end with .git")
}
noSuffixUrl := strings.TrimSuffix(gitUrl, ".git")
urlArr := strings.Split(noSuffixUrl, "/")
return urlArr[ len(urlArr)-1 ], nil
}