diff --git a/main.go b/main.go index 64f129a..1316245 100644 --- a/main.go +++ b/main.go @@ -56,6 +56,11 @@ func main() { Usage: "image attachments for successful builds", EnvVar: "PLUGIN_SUCCESS_IMAGE_ATTACHMENTS", }, + cli.BoolFlag{ + Name: "success_skip_user_notify", + Usage: "skip notifying user for successful builds", + EnvVar: "PLUGIN_SUCCESS_SKIP_USER_NOTIFY", + }, cli.StringFlag{ Name: "failure_username", Usage: "username for failed builds", @@ -78,6 +83,11 @@ func main() { Usage: "image attachments for failed builds", EnvVar: "PLUGIN_FAILURE_IMAGE_ATTACHMENTS", }, + cli.BoolFlag{ + Name: "failure_skip_user_notify", + Usage: "skip notifying user for failed builds", + EnvVar: "PLUGIN_FAILURE_SKIP_USER_NOTIFY", + }, cli.StringFlag{ Name: "repo.fullname", Usage: "repository full name", @@ -220,12 +230,14 @@ func run(c *cli.Context) error { Icon: c.String("success_icon"), Template: c.String("success_template"), ImageAttachments: c.StringSlice("success_image_attachments"), + SkipUserNotify: c.Bool("success_skip_user_notify"), }, Failure: MessageOptions{ Username: c.String("failure_username"), Icon: c.String("failure_icon"), Template: c.String("failure_template"), ImageAttachments: c.StringSlice("failure_image_attachments"), + SkipUserNotify: c.Bool("failure_skip_user_notify"), }, }, } diff --git a/plugin.go b/plugin.go index 0f75514..6208d3f 100644 --- a/plugin.go +++ b/plugin.go @@ -22,6 +22,7 @@ type ( MessageOptions struct { Icon string Username string + SkipUserNotify bool Template string ImageAttachments []string } @@ -95,8 +96,15 @@ func (p Plugin) Exec() error { // get the associated @ string messageOptions := p.createMessage() var userAt string + var skipUserNotify bool - if p.User != nil { + if p.Build.Status == "success" { + skipUserNotify = p.Config.Success.SkipUserNotify + } else { + skipUserNotify = p.Config.Failure.SkipUserNotify + } + + if p.User != nil && !skipUserNotify { userAt = fmt.Sprintf("@%s", p.User.Name) _, _, err := api.PostMessage(userAt, messageOptions) @@ -110,7 +118,7 @@ func (p Plugin) Exec() error { "username": p.User.Name, }).Error("Could not notify user") } - } else { + } else if p.User == nil { userAt = p.Build.Author logrus.WithFields(logrus.Fields{ "author": userAt,