forked from harness/gitness
-
Notifications
You must be signed in to change notification settings - Fork 0
/
email.go
46 lines (40 loc) · 1.29 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
package notify
import "github.com/drone/drone/pkg/mail"
type Email struct {
Recipients []string `yaml:"recipients,omitempty"`
Success string `yaml:"on_success"`
Failure string `yaml:"on_failure"`
}
// Send will send an email, either success or failure,
// based on the Commit Status.
func (e *Email) Send(context *Context) error {
switch {
case context.Commit.Status == "Success" && e.Success != "never":
return e.sendSuccess(context)
case context.Commit.Status == "Failure" && e.Failure != "never":
return e.sendFailure(context)
}
return nil
}
// sendFailure sends email notifications to the list of
// recipients indicating the build failed.
func (e *Email) sendFailure(context *Context) error {
// loop through and email recipients
for _, email := range e.Recipients {
if err := mail.SendFailure(context.Repo.Name, context.Commit.HashShort(), email, context); err != nil {
return err
}
}
return nil
}
// sendSuccess sends email notifications to the list of
// recipients indicating the build was a success.
func (e *Email) sendSuccess(context *Context) error {
// loop through and email recipients
for _, email := range e.Recipients {
if err := mail.SendSuccess(context.Repo.Name, context.Commit.HashShort(), email, context); err != nil {
return err
}
}
return nil
}