2014-02-07 13:10:01 +03:00
|
|
|
package notify
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/drone/drone/pkg/model"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Context represents the context of an
|
|
|
|
// in-progress build request.
|
|
|
|
type Context struct {
|
|
|
|
// Global settings
|
2014-02-12 01:17:35 +03:00
|
|
|
Host string
|
2014-02-07 13:10:01 +03:00
|
|
|
|
|
|
|
// User that owns the repository
|
|
|
|
User *model.User
|
|
|
|
|
|
|
|
// Repository being built.
|
|
|
|
Repo *model.Repo
|
|
|
|
|
|
|
|
// Commit being built
|
|
|
|
Commit *model.Commit
|
|
|
|
}
|
|
|
|
|
|
|
|
type Sender interface {
|
|
|
|
Send(context *Context) error
|
|
|
|
}
|
|
|
|
|
|
|
|
// Notification stores the configuration details
|
|
|
|
// for notifying a user, or group of users,
|
|
|
|
// when their Build has completed.
|
|
|
|
type Notification struct {
|
|
|
|
Email *Email `yaml:"email,omitempty"`
|
|
|
|
Webhook *Webhook `yaml:"webhook,omitempty"`
|
|
|
|
Hipchat *Hipchat `yaml:"hipchat,omitempty"`
|
2014-03-06 21:45:21 +03:00
|
|
|
Irc *IRC `yaml:"irc,omitempty"`
|
2014-03-26 13:43:40 +03:00
|
|
|
Slack *Slack `yaml:"slack,omitempty"`
|
2014-02-07 13:10:01 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func (n *Notification) Send(context *Context) error {
|
|
|
|
// send email notifications
|
2014-02-12 01:17:35 +03:00
|
|
|
if n.Email != nil {
|
|
|
|
n.Email.Send(context)
|
|
|
|
}
|
2014-02-07 13:10:01 +03:00
|
|
|
|
|
|
|
// send email notifications
|
|
|
|
if n.Webhook != nil {
|
|
|
|
n.Webhook.Send(context)
|
|
|
|
}
|
|
|
|
|
|
|
|
// send email notifications
|
|
|
|
if n.Hipchat != nil {
|
|
|
|
n.Hipchat.Send(context)
|
|
|
|
}
|
|
|
|
|
2014-03-06 21:45:21 +03:00
|
|
|
// send irc notifications
|
|
|
|
if n.Irc != nil {
|
|
|
|
n.Irc.Send(context)
|
|
|
|
}
|
2014-02-22 03:10:04 +03:00
|
|
|
|
2014-03-26 13:43:40 +03:00
|
|
|
// send slack notifications
|
|
|
|
if n.Slack != nil {
|
|
|
|
n.Slack.Send(context)
|
|
|
|
}
|
|
|
|
|
2014-02-07 13:10:01 +03:00
|
|
|
return nil
|
|
|
|
}
|