diff --git a/project/project.go b/project/project.go index 3c30a08..0926b2c 100644 --- a/project/project.go +++ b/project/project.go @@ -356,7 +356,12 @@ func applyPullRequestsOverride(c config.Config, modules []Module) []Module { continue } - if strings.Contains(module.Repository, prRepo) { + repoUrl, err := utils.ParseGitHubURL(module.Repository) + if err != nil { + logger.Error("couldn't parse repository URL: %v", err) + } + + if repoUrl.Matches(prRepo) { logger.Debug("Checking out pull-request %s for module %s", pullRequest, module.Name) module.Revision = fmt.Sprintf("pull-request/%d", prNumber) diff --git a/utils/github.go b/utils/github.go index 111f56f..e2afd0e 100644 --- a/utils/github.go +++ b/utils/github.go @@ -68,6 +68,11 @@ func (url GitHubURL) Directory() string { return strings.TrimSuffix(filepath.Base(url.Repository), filepath.Ext(url.Repository)) } +func (url GitHubURL) Matches(match string) bool { + repoName := strings.TrimSuffix(url.Repository, filepath.Ext(url.Repository)) + return strings.Compare(strings.ToLower(repoName), strings.ToLower(match)) == 0 +} + func (url GitHubURL) String() string { return "github://" + url.Repository } diff --git a/utils/github_test.go b/utils/github_test.go index 778a556..f90f4a2 100644 --- a/utils/github_test.go +++ b/utils/github_test.go @@ -53,6 +53,27 @@ func TestParseGitHubURL(t *testing.T) { t.Errorf("expected <%s> but got <%s>", expected, url.HTTPS()) } + // Matches ok + url, _ = ParseGitHubURL("https://github.com/Graylog2/graylog2-server.git") + match := "Graylog2/graylog2-server" + if !url.Matches(match) { + t.Errorf("expected <%s> to match <%s>", url, match) + } + + // Matches case + url, _ = ParseGitHubURL("https://github.com/Graylog2/graylog2-server.git") + match = "GraYloG2/GraYlog2-SErver" + if !url.Matches(match) { + t.Errorf("expected <%s> to match <%s>", url, match) + } + + // Match fails + url, _ = ParseGitHubURL("https://github.com/Graylog2/graylog2-server.git") + match = "Graylog2/graylog2-server-does-not-work" + if url.Matches(match) { + t.Errorf("expected <%s> to not match <%s>", url, match) + } + // Missing .git suffix _, err = ParseGitHubURL("https://github.com/Graylog2/graylog2-server") if err == nil {