Fix repository detection for --pull-requests in checkout command

This commit is contained in:
Bernd Ahlers
2020-08-03 15:47:50 +02:00
parent 725050913b
commit 0ff8279521
3 changed files with 32 additions and 1 deletions

View File

@@ -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)

View File

@@ -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
}

View File

@@ -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 {