Skip to content

Commit

Permalink
fix: Fixing notifier loop for some cases
Browse files Browse the repository at this point in the history
Signed-off-by: Vincent Boutour <[email protected]>
  • Loading branch information
ViBiOh committed Apr 27, 2021
1 parent 1df4b66 commit e5c1b27
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 14 deletions.
6 changes: 5 additions & 1 deletion pkg/notifier/notifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
60 changes: 47 additions & 13 deletions pkg/notifier/notifier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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"),
},
},
},
Expand All @@ -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,
Expand Down

0 comments on commit e5c1b27

Please sign in to comment.