diff --git a/pkg/notifier/notifier.go b/pkg/notifier/notifier.go index 956c8f59..cb4119bb 100644 --- a/pkg/notifier/notifier.go +++ b/pkg/notifier/notifier.go @@ -215,11 +215,15 @@ func (a app) getKetchupToNotify(ctx context.Context, releases []model.Release) ( for _, release := range releases { for index < size { current := ketchups[index] + if release.Repository.ID < current.Repository.ID || (release.Repository.ID == current.Repository.ID && release.Pattern < current.Pattern) { - break + break // release is out of sync, we need to advance } index++ + if release.Repository.ID != current.Repository.ID || release.Pattern != current.Pattern { + continue // ketchup is not sync with release + } if current.Version != release.Version.Name { if userToNotify[current.User] != nil { diff --git a/pkg/notifier/notifier_test.go b/pkg/notifier/notifier_test.go index 93304d33..e141475a 100644 --- a/pkg/notifier/notifier_test.go +++ b/pkg/notifier/notifier_test.go @@ -277,18 +277,39 @@ func TestGetKetchupToNotify(t *testing.T) { app{ketchupService: ketchuptest.New().SetListForRepositories([]model.Ketchup{ { Pattern: model.DefaultPattern, - Repository: model.NewRepository(1, model.Github, repositoryName).AddVersion(model.DefaultPattern, repositoryVersion).AddVersion("latest", repositoryBetaVersion), + Repository: model.NewRepository(1, model.Github, repositoryName), User: model.NewUser(1, testEmail, authModel.NewUser(0, "")), + Version: repositoryVersion, }, { - Pattern: "latest", - Repository: model.NewRepository(1, model.Github, repositoryName).AddVersion(model.DefaultPattern, repositoryVersion).AddVersion("latest", repositoryBetaVersion), + Pattern: model.DefaultPattern, + Repository: model.NewRepository(1, model.Github, repositoryName), + User: model.NewUser(2, "guest@nowhere", authModel.NewUser(0, "")), + Version: repositoryVersion, + }, + { + Pattern: model.DefaultPattern, + Repository: model.NewRepository(2, model.Github, "vibioh/dotfiles"), + User: model.NewUser(1, testEmail, authModel.NewUser(0, "")), + Version: repositoryVersion, + }, + { + Pattern: "^1.1-0", + Repository: model.NewRepository(2, model.Github, "vibioh/dotfiles"), + User: model.NewUser(2, "guest@nowhere", authModel.NewUser(0, "")), + Version: repositoryVersion, + }, + { + Pattern: model.DefaultPattern, + Repository: model.NewRepository(3, model.Github, "vibioh/zzz"), User: model.NewUser(1, testEmail, authModel.NewUser(0, "")), + Version: repositoryVersion, }, { Pattern: model.DefaultPattern, - Repository: model.NewRepository(1, model.Github, repositoryName).AddVersion(model.DefaultPattern, repositoryVersion).AddVersion("latest", repositoryBetaVersion), + Repository: model.NewRepository(3, model.Github, "vibioh/zzz"), User: model.NewUser(2, "guest@nowhere", authModel.NewUser(0, "")), + Version: "1.1.0", }, }, nil)}, args{ @@ -299,14 +320,21 @@ func TestGetKetchupToNotify(t *testing.T) { Version: semver.Version{ Name: "1.1.0", }, - Repository: model.NewRepository(1, model.Github, repositoryName).AddVersion(model.DefaultPattern, repositoryVersion).AddVersion("latest", repositoryBetaVersion), + Repository: model.NewRepository(1, model.Github, repositoryName), }, { - Pattern: "latest", + Pattern: model.DefaultPattern, Version: semver.Version{ - Name: "1.1.0-beta", + Name: "1.1.0", }, - Repository: model.NewRepository(1, model.Github, repositoryName).AddVersion(model.DefaultPattern, repositoryVersion).AddVersion("latest", repositoryBetaVersion), + Repository: model.NewRepository(2, model.Github, "vibioh/dotfiles"), + }, + { + Pattern: model.DefaultPattern, + Version: semver.Version{ + Name: "1.1.0", + }, + Repository: model.NewRepository(3, model.Github, "vibioh/zzz"), }, }, }, @@ -316,20 +344,26 @@ func TestGetKetchupToNotify(t *testing.T) { Version: semver.Version{ Name: "1.1.0", }, - Repository: model.NewRepository(1, model.Github, repositoryName).AddVersion(model.DefaultPattern, repositoryVersion).AddVersion("latest", repositoryBetaVersion), + Repository: model.NewRepository(1, model.Github, repositoryName), }}, {ID: 1, Email: testEmail}: {{ - Pattern: "latest", + Pattern: model.DefaultPattern, Version: semver.Version{ - Name: "1.1.0-beta", + Name: "1.1.0", + }, + Repository: model.NewRepository(1, model.Github, repositoryName), + }, { + Pattern: model.DefaultPattern, + Version: semver.Version{ + Name: "1.1.0", }, - Repository: model.NewRepository(1, model.Github, repositoryName).AddVersion(model.DefaultPattern, repositoryVersion).AddVersion("latest", repositoryBetaVersion), + Repository: model.NewRepository(2, model.Github, "vibioh/dotfiles"), }, { Pattern: model.DefaultPattern, Version: semver.Version{ Name: "1.1.0", }, - Repository: model.NewRepository(1, model.Github, repositoryName).AddVersion(model.DefaultPattern, repositoryVersion).AddVersion("latest", repositoryBetaVersion), + Repository: model.NewRepository(3, model.Github, "vibioh/zzz"), }}, }, nil,