feat(notifications): add general notification delay (#1246)

This commit is contained in:
lazou 2022-03-09 11:03:06 +01:00 committed by GitHub
parent f79e4b5435
commit a5c60a9fe6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 91 additions and 12 deletions

View file

@ -45,7 +45,7 @@ func AppendLegacyUrls(urls []string, cmd *cobra.Command, title string) ([]string
log.WithError(err).Fatal("could not read notifications argument")
}
delay := time.Duration(0)
legacyDelay := time.Duration(0)
for _, t := range types {
@ -76,14 +76,29 @@ func AppendLegacyUrls(urls []string, cmd *cobra.Command, title string) ([]string
urls = append(urls, shoutrrrURL)
if delayNotifier, ok := legacyNotifier.(ty.DelayNotifier); ok {
delay = delayNotifier.GetDelay()
legacyDelay = delayNotifier.GetDelay()
}
log.WithField("URL", shoutrrrURL).Trace("created Shoutrrr URL from legacy notifier")
}
delay := GetDelay(cmd, legacyDelay)
return urls, delay
}
// GetDelay returns the legacy delay if defined, otherwise the delay as set by args is returned
func GetDelay(c *cobra.Command, legacyDelay time.Duration) time.Duration {
if legacyDelay > 0 {
return legacyDelay
}
delay, _ := c.PersistentFlags().GetInt("notifications-delay")
if delay > 0 {
return time.Duration(delay) * time.Second
}
return time.Duration(0)
}
// GetTitle returns a common notification title with hostname appended
func GetTitle(hostname string) string {
title := "Watchtower updates"