MCPcopy Create free account
hub / github.com/cli/cli / parseGitRepo

Function parseGitRepo

script/ghmock/gitfixture.go:26–42  ·  view source on GitHub ↗
(name string)

Source from the content-addressed store, hash-verified

24var gitHostName = regexp.MustCompile(`^[A-Za-z0-9][A-Za-z0-9.-]*$`)
25
26func 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
44func gitRepoPath(world, host, repo string) string {
45 if host == mockHost || host == "ssh.github.com" {

Callers 4

serveGitHTTPMethod · 0.85
cmdGitSSHFunction · 0.85
parseRepoArgsFunction · 0.85
cmdRepoFunction · 0.85

Calls 2

JoinMethod · 0.80
ErrorfMethod · 0.65

Tested by

no test coverage detected