(name string)
| 24 | var gitHostName = regexp.MustCompile(`^[A-Za-z0-9][A-Za-z0-9.-]*$`) |
| 25 | |
| 26 | func parseGitRepo(name string) (host, repo string, err error) { |
| 27 | parts := strings.Split(name, "/") |
| 28 | host = dotcomHost |
| 29 | if len(parts) == 3 { |
| 30 | host, parts = parts[0], parts[1:] |
| 31 | } |
| 32 | if !gitHostName.MatchString(host) || len(parts) != 2 { |
| 33 | return "", "", fmt.Errorf("invalid repository %q; use [HOST/]OWNER/REPO", name) |
| 34 | } |
| 35 | parts[1] = strings.TrimSuffix(parts[1], ".git") |
| 36 | for _, p := range parts { |
| 37 | if !gitNamePart.MatchString(p) || strings.HasSuffix(p, ".") { |
| 38 | return "", "", fmt.Errorf("invalid repository %q; use [HOST/]OWNER/REPO", name) |
| 39 | } |
| 40 | } |
| 41 | return strings.ToLower(host), strings.Join(parts, "/"), nil |
| 42 | } |
| 43 | |
| 44 | func gitRepoPath(world, host, repo string) string { |
| 45 | if host == mockHost || host == "ssh.github.com" { |
no test coverage detected