SplitGithubRemote splits a GitHub remote URL into a Github account and repository name.
(remote string)
| 11 | |
| 12 | // SplitGithubRemote splits a GitHub remote URL into a Github account and repository name. |
| 13 | func SplitGithubRemote(remote string) (account, repo string, ok bool) { |
| 14 | ep, err := transport.NewEndpoint(remote) |
| 15 | if err != nil { |
| 16 | return "", "", false |
| 17 | } |
| 18 | |
| 19 | if ep.Host != "github.com" { |
| 20 | return "", "", false |
| 21 | } |
| 22 | |
| 23 | account, repo = path.Split(ep.Path) |
| 24 | account = strings.Trim(account, "/") |
| 25 | repo = strings.TrimSuffix(repo, ".git") |
| 26 | if account == "" || repo == "" || strings.Contains(account, "/") { |
| 27 | return "", "", false |
| 28 | } |
| 29 | |
| 30 | return account, repo, true |
| 31 | } |
| 32 | |
| 33 | // NormalizeGithubRemote validates and converts a Git remote to a normalized HTTPS Github URL ending in .git. |
| 34 | func NormalizeGithubRemote(remote string) (string, error) { |