-
Notifications
You must be signed in to change notification settings - Fork 18
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
daemon: send slack notifications (#281) #585
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a great start, awesome work @terryz21 😁 I've left a few comments - let me know if you have any questions!
daemon/inertiad/notifier/notifier.go
Outdated
return err | ||
} | ||
|
||
_ = resp //note: temporary, may need response in the future? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we definitely want to check the resp here, at least for status codes (ie if its not 2xx
then Slack rejected the request)
daemon/inertiad/notifier/notifier.go
Outdated
|
||
// 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we probably want to make this URL configurable, ie with
func NewNotifier(webhook string) *SlackNotifier
also 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
another idea - if a empty string is provided, the notifier should become a no-op notifier (ie it doesn't do anything on Notify()
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 <[email protected]>
Co-Authored-By: terryz21 <[email protected]>
Co-Authored-By: terryz21 <[email protected]>
… 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.
|
daemon/inertiad/notifier/notifier.go
Outdated
|
||
// 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
only really need to leave comments if the code is not self-explanatory 😋
// check if url is empty | |
// check if url is empty |
daemon/inertiad/notifier/notifier.go
Outdated
return err | ||
} | ||
defer resp.Body.Close() | ||
body, err := ioutil.ReadAll(resp.Body) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should check error here
daemon/inertiad/notifier/notifier.go
Outdated
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
almost there 😁
🎟️ Ticket(s): Closes #281, created #621 for follow-up
👷 Changes
🔦 Testing Instructions
Explain how to test your changes, if applicable.