2014-02-07 10:10:01 +00:00
|
|
|
package notify
|
|
|
|
|
|
|
|
import (
|
2014-08-03 21:45:50 +00:00
|
|
|
"log"
|
|
|
|
|
|
|
|
"github.com/drone/drone/plugin/notify/email"
|
2014-08-03 23:10:04 +00:00
|
|
|
"github.com/drone/drone/plugin/notify/github"
|
2014-06-12 23:41:04 +00:00
|
|
|
"github.com/drone/drone/shared/model"
|
2014-02-07 10:10:01 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type Sender interface {
|
2014-07-13 02:01:34 +00:00
|
|
|
Send(context *model.Request) error
|
2014-02-07 10:10:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Notification stores the configuration details
|
|
|
|
// for notifying a user, or group of users,
|
|
|
|
// when their Build has completed.
|
|
|
|
type Notification struct {
|
2014-08-03 21:45:50 +00:00
|
|
|
Email *email.Email `yaml:"email,omitempty"`
|
|
|
|
Webhook *Webhook `yaml:"webhook,omitempty"`
|
|
|
|
Hipchat *Hipchat `yaml:"hipchat,omitempty"`
|
|
|
|
Irc *IRC `yaml:"irc,omitempty"`
|
|
|
|
Slack *Slack `yaml:"slack,omitempty"`
|
2014-08-03 23:10:04 +00:00
|
|
|
|
2014-08-14 18:41:56 +00:00
|
|
|
GitHub github.GitHub `yaml:"--"`
|
2014-02-07 10:10:01 +00:00
|
|
|
}
|
|
|
|
|
2014-07-13 02:01:34 +00:00
|
|
|
func (n *Notification) Send(context *model.Request) error {
|
2014-02-07 10:10:01 +00:00
|
|
|
// send email notifications
|
2014-08-03 21:45:50 +00:00
|
|
|
if n.Email != nil {
|
|
|
|
err := n.Email.Send(context)
|
|
|
|
if err != nil {
|
|
|
|
log.Println(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// send webhook notifications
|
2014-02-07 10:10:01 +00:00
|
|
|
if n.Webhook != nil {
|
2014-08-03 21:45:50 +00:00
|
|
|
err := n.Webhook.Send(context)
|
|
|
|
if err != nil {
|
|
|
|
log.Println(err)
|
|
|
|
}
|
2014-02-07 10:10:01 +00:00
|
|
|
}
|
|
|
|
|
2014-08-03 21:45:50 +00:00
|
|
|
// send hipchat notifications
|
2014-02-07 10:10:01 +00:00
|
|
|
if n.Hipchat != nil {
|
2014-08-03 21:45:50 +00:00
|
|
|
err := n.Hipchat.Send(context)
|
|
|
|
if err != nil {
|
|
|
|
log.Println(err)
|
|
|
|
}
|
2014-02-07 10:10:01 +00:00
|
|
|
}
|
|
|
|
|
2014-03-06 18:45:21 +00:00
|
|
|
// send irc notifications
|
|
|
|
if n.Irc != nil {
|
2014-08-03 21:45:50 +00:00
|
|
|
err := n.Irc.Send(context)
|
|
|
|
if err != nil {
|
|
|
|
log.Println(err)
|
|
|
|
}
|
2014-03-06 18:45:21 +00:00
|
|
|
}
|
2014-02-22 00:10:04 +00:00
|
|
|
|
2014-03-26 10:43:40 +00:00
|
|
|
// send slack notifications
|
|
|
|
if n.Slack != nil {
|
2014-08-03 21:45:50 +00:00
|
|
|
err := n.Slack.Send(context)
|
|
|
|
if err != nil {
|
|
|
|
log.Println(err)
|
|
|
|
}
|
2014-03-26 10:43:40 +00:00
|
|
|
}
|
|
|
|
|
2014-08-03 23:10:04 +00:00
|
|
|
// send email notifications
|
2014-08-14 19:36:45 +00:00
|
|
|
// TODO (bradrydzewski) need to improve this code
|
|
|
|
githubStatus := new(github.GitHub)
|
|
|
|
if err := githubStatus.Send(context); err != nil {
|
2014-08-03 23:10:04 +00:00
|
|
|
log.Println(err)
|
|
|
|
}
|
|
|
|
|
2014-02-07 10:10:01 +00:00
|
|
|
return nil
|
|
|
|
}
|