Skip to content

Commit

Permalink
fix: improve robustness of .Summary template
Browse files Browse the repository at this point in the history
  • Loading branch information
garethgeorge committed Jun 13, 2024
1 parent 879e39c commit 7940642
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions internal/hook/hookvars.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,8 @@ func (v HookVars) Summary() (string, error) {
return v.renderTemplate(templateForSnapshotStart)
case v1.Hook_CONDITION_SNAPSHOT_END, v1.Hook_CONDITION_SNAPSHOT_WARNING, v1.Hook_CONDITION_SNAPSHOT_SUCCESS:
return v.renderTemplate(templateForSnapshotEnd)
case v1.Hook_CONDITION_ANY_ERROR, v1.Hook_CONDITION_SNAPSHOT_ERROR, v1.Hook_CONDITION_CHECK_ERROR, v1.Hook_CONDITION_PRUNE_ERROR:
return v.renderTemplate(templateForError)
default:
return "unknown event", nil
return v.renderTemplate(templateDefault)
}
}

Expand All @@ -133,12 +131,18 @@ func (v HookVars) renderTemplate(templ string) (string, error) {
return buf.String(), nil
}

var defaultTemplate = `
var templateDefault = `
{{ if .Error -}}
Backrest Notification for Error
Task: "{{ .Task }}" at {{ .FormatTime .CurTime }}
Backrest Error
Task: {{ .Task }} at {{ .FormatTime .CurTime }}
Event: {{ .EventName .Event }}
Repo: {{ .Repo.Id }}
Error: {{ .Error }}
{{ else -}}
Backrest Notification
Task: {{ .Task }} at {{ .FormatTime .CurTime }}
Event: {{ .EventName .Event }}
{{ end }}
`

var templateForSnapshotEnd = `
Expand Down Expand Up @@ -169,12 +173,6 @@ Backup Statistics:
{{ end }}
{{ end }}`

var templateForError = `
{{ if .Error -}}
Error: {{ .Error }}
{{ end }}
`

var templateForSnapshotStart = `
Backrest Notification for Snapshot Start
Task: "{{ .Task }}" at {{ .FormatTime .CurTime }}
Expand Down

0 comments on commit 7940642

Please sign in to comment.