Merge pull request #1067 from etix/master

slack: implement on_change
This commit is contained in:
Brad Rydzewski 2015-08-03 00:52:40 -07:00
commit 57bcab18a9

View file

@ -24,16 +24,21 @@ type Slack struct {
Started bool `yaml:"on_started,omitempty"` Started bool `yaml:"on_started,omitempty"`
Success bool `yaml:"on_success,omitempty"` Success bool `yaml:"on_success,omitempty"`
Failure bool `yaml:"on_failure,omitempty"` Failure bool `yaml:"on_failure,omitempty"`
Change bool `yaml:"on_change,omitempty"`
} }
func (s *Slack) Send(context *model.Request) error { func (s *Slack) Send(context *model.Request) error {
switch { switch {
case context.Commit.Status == "Started" && s.Started: case context.Commit.Status == "Started" && s.Started:
return s.sendStarted(context) return s.sendStarted(context)
case context.Commit.Status == "Success" && s.Success: case context.Commit.Status == "Success":
return s.sendSuccess(context) if s.Success || (s.Change && context.Prior.Status != context.Commit.Status) {
case context.Commit.Status == "Failure" && s.Failure: return s.sendSuccess(context)
return s.sendFailure(context) }
case context.Commit.Status == "Failure":
if s.Failure || (s.Change && context.Prior.Status != context.Commit.Status) {
return s.sendFailure(context)
}
} }
return nil return nil