daemon: send slack notifications (#281)#585
Conversation
| return err | ||
| } | ||
|
|
||
| _ = resp //note: temporary, may need response in the future? |
There was a problem hiding this comment.
we definitely want to check the resp here, at least for status codes (ie if its not 2xx then Slack rejected the request)
|
|
||
| // NewNotifier creates a notifier with web hook url to slack channel | ||
| func NewNotifier() *SlackNotifier { | ||
| url := "https://hooks.slack.com/services/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" |
There was a problem hiding this comment.
we probably want to make this URL configurable, ie with
func NewNotifier(webhook string) *SlackNotifieralso it's fine for now because the Slack workspace is a test one, but we want to avoid committing sensitive information into the repository (although this workspace might be useful for running integration tests, assuming it'll always be available for use)
There was a problem hiding this comment.
another idea - if a empty string is provided, the notifier should become a no-op notifier (ie it doesn't do anything on Notify())
yaoharry
left a comment
There was a problem hiding this comment.
Should unstage unchanged files ex: *.png, compiled.go, id_rsa.
|
Thanks for the comments! I will make these changes along with some of the formatting additions this week |
Co-Authored-By: terryz21 <38884362+terryz21@users.noreply.github.com>
Co-Authored-By: terryz21 <38884362+terryz21@users.noreply.github.com>
Co-Authored-By: terryz21 <38884362+terryz21@users.noreply.github.com>
… daemon/#281-slack-notifier
…r configuring slack webhook URL.
… replaced with comma previously
Codecov Report
@@ Coverage Diff @@
## master #585 +/- ##
==========================================
- Coverage 55.88% 55.81% -0.07%
==========================================
Files 68 68
Lines 3377 3385 +8
==========================================
+ Hits 1887 1889 +2
- Misses 1248 1253 +5
- Partials 242 243 +1
Continue to review full report at Codecov.
|
|
|
||
| // Notify sends the notification | ||
| func (n *SlackNotifier) Notify(text string, options *NotifyOptions) error { | ||
| // check if url is empty |
There was a problem hiding this comment.
only really need to leave comments if the code is not self-explanatory 😋
| // check if url is empty | |
| // check if url is empty |
| return err | ||
| } | ||
| defer resp.Body.Close() | ||
| body, err := ioutil.ReadAll(resp.Body) |
| bodyString := string(body) | ||
|
|
||
| if resp.StatusCode < 200 || resp.StatusCode > 299 { | ||
| return errors.New("Http request rejected by Slack. Error: " + bodyString) |
There was a problem hiding this comment.
lowercase for go error convention:
| return errors.New("Http request rejected by Slack. Error: " + bodyString) | |
| return errors.New("http request rejected by Slack. Error: " + bodyString) |

🎟️ Ticket(s): Closes #281, created #621 for follow-up
👷 Changes
🔦 Testing Instructions
Explain how to test your changes, if applicable.