forked from evergreen-ci/evergreen
/
email.go
94 lines (79 loc) · 2.55 KB
/
email.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package notify
import (
"strings"
"github.com/evergreen-ci/evergreen/util"
"github.com/mongodb/grip"
)
// Interface around an email that may be sent as a notification. Provides
// getters for body, subject, and change info, and functions to determine
// if this email should be skipped.
type Email interface {
GetBody() string
GetSubject() string
// for system-related failures, we only want to notify the admins
// regardless of who the default recipient is
IsLikelySystemFailure() bool
GetRecipients(defaultRecipient string) []string
GetChangeInfo() []ChangeInfo
// Should you skip sending this email given the provided variants to skip
ShouldSkip(skipVariants []string) bool
}
// "Base class" for structs that implement the Email interface. Stores the
// basics that any email should have.
type EmailBase struct {
Body string
Subject string
ChangeInfo []ChangeInfo
}
func (self *EmailBase) GetBody() string {
return self.Body
}
func (self *EmailBase) GetSubject() string {
return self.Subject
}
func (self *EmailBase) GetChangeInfo() []ChangeInfo {
return self.ChangeInfo
}
// Implements Email interface for build-specific emails. Defines skip logic for
// emails specific to build
type BuildEmail struct {
EmailBase
Trigger TriggeredBuildNotification
}
func (self *BuildEmail) ShouldSkip(skipVariants []string) bool {
buildVariant := self.Trigger.Current.BuildVariant
if util.SliceContains(skipVariants, buildVariant) {
grip.Debugf("Skipping buildvariant %s '%s' notification: '%s'",
buildVariant, self.Trigger.Key.NotificationName, self.Subject)
return true
}
return false
}
func (self *BuildEmail) IsLikelySystemFailure() bool {
return false
}
func (self *BuildEmail) GetRecipients(defaultRecipient string) []string {
return []string{defaultRecipient}
}
// Implements Email interface for task-specific emails. Defines skip logic for
// emails specific to tasks
type TaskEmail struct {
EmailBase
Trigger TriggeredTaskNotification
}
func (self *TaskEmail) ShouldSkip(skipVariants []string) bool {
// skip the buildvariant notification if necessary
buildVariant := self.Trigger.Current.BuildVariant
if util.SliceContains(skipVariants, buildVariant) {
grip.Debugf("Skipping buildvariant %s '%s' notification: '%s'",
buildVariant, self.Trigger.Key.NotificationName, self.Subject)
return true
}
return false
}
func (self *TaskEmail) IsLikelySystemFailure() bool {
return strings.Contains(self.GetSubject(), UnresponsiveMessage)
}
func (self *TaskEmail) GetRecipients(defaultRecipient string) []string {
return []string{defaultRecipient}
}