Skip to content

Commit

Permalink
feat: Adding update for weekly notifications too
Browse files Browse the repository at this point in the history
Signed-off-by: Vincent Boutour <[email protected]>
  • Loading branch information
ViBiOh committed Oct 5, 2021
1 parent fee6437 commit 11b0165
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions pkg/notifier/notifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func (a App) getKetchupToNotify(ctx context.Context, releases []model.Release) (
}

logger.Info("%d weekly ketchups to notify", len(weeklyKetchups))
addWeeklyKetchups(weeklyKetchups, userToNotify)
a.addWeeklyKetchups(weeklyKetchups, userToNotify)
}

logger.Info("%d users to notify", len(userToNotify))
Expand Down Expand Up @@ -211,7 +211,7 @@ func (a App) syncReleasesByUser(releases []model.Release, ketchups []model.Ketch
return usersToNotify
}

func addWeeklyKetchups(ketchups []model.Ketchup, usersToNotify map[model.User][]model.Release) {
func (a App) addWeeklyKetchups(ketchups []model.Ketchup, usersToNotify map[model.User][]model.Release) {
for _, ketchup := range ketchups {
ketchupVersion, err := semver.Parse(ketchup.Version)
if err != nil {
Expand All @@ -226,6 +226,12 @@ func addWeeklyKetchups(ketchups []model.Ketchup, usersToNotify map[model.User][]
} else {
usersToNotify[ketchup.User] = []model.Release{release}
}

if ketchup.UpdateWhenNotify {
if err := a.ketchupService.UpdateVersion(context.Background(), ketchup.Repository.ID, ketchup.User.ID, ketchup.Pattern, release.Version.Name); err != nil {
logger.Error("unable to update ketchup user=%d repository=%d: %s", ketchup.User.ID, ketchup.Repository.ID, err)
}
}
}
}

Expand Down

0 comments on commit 11b0165

Please sign in to comment.