1
0
mirror of https://github.com/taigrr/wtf synced 2025-01-18 04:03:14 -08:00

Add config option to hide empty OpsGenie schedules

This commit is contained in:
Chris Cummer 2018-05-15 10:45:11 -07:00
parent f05aa903dc
commit 397fcbca9a

View File

@ -53,21 +53,28 @@ func (widget *Widget) Refresh() {
func (widget *Widget) contentFrom(onCallResponse *OnCallResponse) string { func (widget *Widget) contentFrom(onCallResponse *OnCallResponse) string {
str := "" str := ""
for _, data := range onCallResponse.OnCallData { hideEmpty := Config.UBool("wtf.mods.opsgenie.hideEmpty", false)
str = str + fmt.Sprintf(" [green]%s[white]\n", widget.cleanScheduleName(data.Parent.Name))
if len(data.Recipients) == 0 { for _, data := range onCallResponse.OnCallData {
str = str + " [gray]no one[white]\n" if (len(data.Recipients) == 0) && (hideEmpty == true) {
} else { continue
str = str + fmt.Sprintf(" %s\n", strings.Join(wtf.NamesFromEmails(data.Recipients), ", "))
} }
str = str + "\n" var msg string
if len(data.Recipients) == 0 {
msg = " [gray]no one[white]\n\n"
} else {
msg = fmt.Sprintf(" %s\n\n", strings.Join(wtf.NamesFromEmails(data.Recipients), ", "))
}
str = str + widget.cleanScheduleName(data.Parent.Name)
str = str + msg
} }
return str return str
} }
func (widget *Widget) cleanScheduleName(schedule string) string { func (widget *Widget) cleanScheduleName(schedule string) string {
return strings.Replace(schedule, "_", " ", -1) cleanedName := strings.Replace(schedule, "_", " ", -1)
return fmt.Sprintf(" [green]%s[white]\n", cleanedName)
} }