mirror of
https://github.com/Graylog2/graylog-project-cli.git
synced 2026-03-13 08:02:57 +08:00
Fix repository detection for --pull-requests in checkout command
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user