Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add flag to skip notifying user #45

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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"),
},
},
}
Expand Down
12 changes: 10 additions & 2 deletions plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type (
MessageOptions struct {
Icon string
Username string
SkipUserNotify bool
Template string
ImageAttachments []string
}
Expand Down Expand Up @@ -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)
Expand All @@ -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,
Expand Down