SplitGithubRemote takes a GitHub HTTPS remote URL and extracts the Github account and repository name.
(remote string)
| 9 | |
| 10 | // SplitGithubRemote takes a GitHub HTTPS remote URL and extracts the Github account and repository name. |
| 11 | func SplitGithubRemote(remote string) (account, repo string, ok bool) { |
| 12 | ep, err := transport.NewEndpoint(remote) |
| 13 | if err != nil { |
| 14 | return "", "", false |
| 15 | } |
| 16 | |
| 17 | if ep.Host != "github.com" { |
| 18 | return "", "", false |
| 19 | } |
| 20 | |
| 21 | account, repo = path.Split(ep.Path) |
| 22 | account = strings.Trim(account, "/") |
| 23 | repo = strings.TrimSuffix(repo, ".git") |
| 24 | if account == "" || repo == "" || strings.Contains(account, "/") { |
| 25 | return "", "", false |
| 26 | } |
| 27 | |
| 28 | return account, repo, true |
| 29 | } |
no test coverage detected