Skip to content

Commit

Permalink
Add test and allowance for gitlab to also be case insensitive
Browse files Browse the repository at this point in the history
Signed-off-by: Josh Cogan <[email protected]>
  • Loading branch information
joshgc committed Aug 25, 2023
1 parent 68a9dfb commit 934911b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
4 changes: 3 additions & 1 deletion cmd/package_managers.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ func makeGithubRepo(urlAndPathParts []string) string {
return fmt.Sprintf("https://github.com/%s/%s", userOrOrg, repoName)
}

// Both GitHub and GitLab are case insensitive (and thus we lowercase those URLS)
// however generic URLs are indeed case sensitive!
var pypiMatchers = []func(string) string{
func(url string) string {
return makeGithubRepo(githubDomainRegexp.FindStringSubmatch(url))
Expand All @@ -57,7 +59,7 @@ var pypiMatchers = []func(string) string{
func(url string) string {
match := gitlabDomainRegexp.FindStringSubmatch(url)
if len(match) >= 3 {
return fmt.Sprintf("https://gitlab.com/%s/%s", match[1], match[2])
return strings.ToLower(fmt.Sprintf("https://gitlab.com/%s/%s", match[1], match[2]))
}
return ""
},
Expand Down
17 changes: 17 additions & 0 deletions cmd/package_managers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,23 @@ func Test_findGitRepositoryInPYPIResponse(t *testing.T) {
}
}
}
`,
want: "https://github.com/htaslan/color",
wantErrStr: "",
},
{
name: "findGitRepositoryInPYPIResponse_dedup_gitlab",
partialPYPIResponse: `
{
"info": {
"platform": "UNKNOWN",
"project_url": "foo",
"project_urls": {
"RandomKey": "https://gitlab.com/htaslan/color/",
"raNdoMkEY": "https://gitlab.com/hTASLan/color"
}
}
}
`,
want: "https://github.com/htaslan/color",
wantErrStr: "",
Expand Down

0 comments on commit 934911b

Please sign in to comment.