harness-drone/shared/notify/notification.go

68 lines
1.3 KiB
Go
Raw Normal View History

2014-02-07 10:10:01 +00:00
package notify
import (
2014-06-04 21:25:38 +00:00
"github.com/drone/drone/server/resource/commit"
"github.com/drone/drone/server/resource/repo"
"github.com/drone/drone/server/resource/user"
2014-02-07 10:10:01 +00:00
)
// Context represents the context of an
// in-progress build request.
type Context struct {
// Global settings
Host string
2014-02-07 10:10:01 +00:00
// User that owns the repository
2014-06-04 21:25:38 +00:00
User *user.User
2014-02-07 10:10:01 +00:00
// Repository being built.
2014-06-04 21:25:38 +00:00
Repo *repo.Repo
2014-02-07 10:10:01 +00:00
// Commit being built
2014-06-04 21:25:38 +00:00
Commit *commit.Commit
2014-02-07 10:10:01 +00:00
}
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 18:45:21 +00:00
Irc *IRC `yaml:"irc,omitempty"`
2014-03-26 10:43:40 +00:00
Slack *Slack `yaml:"slack,omitempty"`
2014-02-07 10:10:01 +00:00
}
func (n *Notification) Send(context *Context) error {
// send email notifications
if n.Email != nil {
n.Email.Send(context)
}
2014-02-07 10:10:01 +00: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 18:45:21 +00:00
// send irc notifications
if n.Irc != nil {
n.Irc.Send(context)
}
2014-03-26 10:43:40 +00:00
// send slack notifications
if n.Slack != nil {
n.Slack.Send(context)
}
2014-02-07 10:10:01 +00:00
return nil
}