Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions detect_github.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,17 @@ func (d *GitHubDetector) Detect(src, _ string) (string, bool, error) {
}

func (d *GitHubDetector) detectHTTP(src string) (string, bool, error) {
parts := strings.Split(src, "/")
if len(parts) < 3 {
parts := strings.Split(src, "?")
if len(parts) > 2 {
return "", false, fmt.Errorf("there is more than 1 '?' in the URL")
}
hostAndPath := parts[0]
hostAndPathParts := strings.Split(hostAndPath, "/")
if len(hostAndPathParts) < 3 {
return "", false, fmt.Errorf(
"GitHub URLs should be github.com/username/repo")
}

urlStr := fmt.Sprintf("https://%s", strings.Join(parts[:3], "/"))
urlStr := fmt.Sprintf("https://%s", strings.Join(hostAndPathParts[:3], "/"))
url, err := url.Parse(urlStr)
if err != nil {
return "", true, fmt.Errorf("error parsing GitHub URL: %s", err)
Expand All @@ -39,8 +43,12 @@ func (d *GitHubDetector) detectHTTP(src string) (string, bool, error) {
url.Path += ".git"
}

if len(parts) > 3 {
url.Path += "//" + strings.Join(parts[3:], "/")
if len(hostAndPathParts) > 3 {
url.Path += "//" + strings.Join(hostAndPathParts[3:], "/")
}

if len(parts) == 2 {
url.RawQuery = parts[1]
}

return "git::" + url.String(), true, nil
Expand Down
4 changes: 4 additions & 0 deletions detect_github_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ func TestGitHubDetector(t *testing.T) {
"github.com/hashicorp/foo.git?foo=bar",
"git::https://github.com/hashicorp/foo.git?foo=bar",
},
{
"github.com/hashicorp/foo.git?foo=bar/foobar,barfoo=bar",
"git::https://github.com/hashicorp/foo.git?foo=bar/foobar,barfoo=bar",
},
}

pwd := "/pwd"
Expand Down