Skip to content

Commit

Permalink
Make Slack notifications less spammy
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Baecher committed Feb 26, 2018
1 parent 52e45df commit 50376e4
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 42 deletions.
9 changes: 9 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changes

## ?.?.?

### Bugfixes and minor changes

* Slack notifier is now less spammy.


## 1.0.0

Major changes on frontend and backend. The API contains breaking changes, but neither the Go nor the PHP client are affected by these changes.
Expand All @@ -24,6 +31,7 @@ Major changes on frontend and backend. The API contains breaking changes, but ne
* Unknown API routes now properly return 404.
* Unknown frontend routes now redirect to the home page.


## 0.8.0

This is the first versioned release.
Expand All @@ -37,6 +45,7 @@ This is the first versioned release.
* Names with spaces, slashes, and various other characters no longer break the UI.
* Fix typescript error with moment.js.


## 0.0.0

This corresponds to everything up to commit `3637a6e` (inclusive) made on Jan 29, 2018.
26 changes: 13 additions & 13 deletions glide.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion glide.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import:
- engine
- engine/standard
- middleware
- package: github.com/lytics/slackhook
- package: github.com/rubenv/sql-migrate
- package: github.com/stretchr/testify
subpackages:
Expand All @@ -23,3 +22,4 @@ import:
- package: github.com/satori/go.uuid
- package: github.com/MEDIGO/go-healthz
- package: gopkg.in/gorp.v1
- package: github.com/vsco/slackhook
51 changes: 23 additions & 28 deletions notifier/slack_notifier.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package notifier

import "github.com/lytics/slackhook"
import (
"fmt"

"github.com/vsco/slackhook"
)

// SlackNotifier is a notifier that send messages to Slack.
type SlackNotifier struct {
Expand All @@ -14,38 +18,29 @@ func NewSlackNotifier(url string) Notifier {

// NotifyStatusChange notifies a change in the status of a flag.
func (n *SlackNotifier) NotifyStatusChange(feature string, status bool, environment string) error {
text := "disabled"
color := "#e74c3c"

if status {
text = "enabled"
color = "#27ae60"
}
text := fmt.Sprintf("Feature *%s* is now %s in *%s*.", feature, label(status), environment)

return n.client.Send(&slackhook.Message{
Text: "WOOF! WOFF! ARH-WOOOOOOOO!",
Attachments: []*slackhook.Attachment{
&slackhook.Attachment{
Title: "Laika Flag Update!",
Color: color,
Fields: []slackhook.Field{
slackhook.Field{
Title: "Flag",
Value: feature,
Short: false,
},
slackhook.Field{
Title: "Environment",
Value: environment,
Short: true,
},
slackhook.Field{
Title: "Status",
Value: text,
Short: true,
},
},
Text: text,
Color: color(status),
MarkdownIn: []string{"text"},
},
},
})
}

func color(status bool) string {
if status {
return "good"
}
return "danger"
}

func label(status bool) string {
if status {
return "enabled"
}
return "disabled"
}

0 comments on commit 50376e4

Please sign in to comment.