9 // GitHubDetector implements Detector to detect GitHub URLs and turn
10 // them into URLs that the Git Getter can understand.
11 type GitHubDetector struct{}
13 func (d *GitHubDetector) Detect(src, _ string) (string, bool, error) {
18 if strings.HasPrefix(src, "github.com/") {
19 return d.detectHTTP(src)
25 func (d *GitHubDetector) detectHTTP(src string) (string, bool, error) {
26 parts := strings.Split(src, "/")
28 return "", false, fmt.Errorf(
29 "GitHub URLs should be github.com/username/repo")
32 urlStr := fmt.Sprintf("https://%s", strings.Join(parts[:3], "/"))
33 url, err := url.Parse(urlStr)
35 return "", true, fmt.Errorf("error parsing GitHub URL: %s", err)
38 if !strings.HasSuffix(url.Path, ".git") {
43 url.Path += "//" + strings.Join(parts[3:], "/")
46 return "git::" + url.String(), true, nil