FromURL extracts the GitHub repository information from a git remote URL
(u *url.URL)
| 59 | |
| 60 | // FromURL extracts the GitHub repository information from a git remote URL |
| 61 | func FromURL(u *url.URL) (Interface, error) { |
| 62 | if u.Hostname() == "" { |
| 63 | return nil, fmt.Errorf("no hostname detected") |
| 64 | } |
| 65 | |
| 66 | parts := strings.SplitN(strings.Trim(u.Path, "/"), "/", 3) |
| 67 | if len(parts) != 2 { |
| 68 | return nil, fmt.Errorf("invalid path: %s", u.Path) |
| 69 | } |
| 70 | |
| 71 | return NewWithHost(parts[0], strings.TrimSuffix(parts[1], ".git"), u.Hostname()), nil |
| 72 | } |
| 73 | |
| 74 | func normalizeHostname(h string) string { |
| 75 | return strings.ToLower(strings.TrimPrefix(h, "www.")) |