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

daemon: send slack notifications (#281) #585

Merged
merged 15 commits into from
Oct 3, 2019
Merged

Conversation

terryz21
Copy link
Contributor

@terryz21 terryz21 commented Feb 24, 2019

🎟️ Ticket(s): Closes #281, created #621 for follow-up


👷 Changes

  • A new file called Notifier was created in daemon to contain Notifier.go which handles how slack notifications are sent via Incoming Webhooks.
  • Notify() method called in Deploy() and makes POST request to send message to slack
  • For now, only notifies "Build started" & "Build completed"

🔦 Testing Instructions

Explain how to test your changes, if applicable.

  • Need create your own Slack workspace and install your own slack app. Follow the instructions in this link: https://api.slack.com/incoming-webhooks#advanced_message_formatting
  • Once you create your own Slack app, copy the generated Webhook URL for the channel you want to post and set it as the url field in NewNotifier method
  • Run tests in deployment_test.go

@terryz21 terryz21 requested a review from a team February 24, 2019 11:55
@ghost ghost requested review from kimoantiqe and seifghazi February 24, 2019 11:55
Copy link
Member

@bobheadxi bobheadxi left a 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/main.go Outdated Show resolved Hide resolved
return err
}

_ = resp //note: temporary, may need response in the future?
Copy link
Member

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 Show resolved Hide resolved

// NewNotifier creates a notifier with web hook url to slack channel
func NewNotifier() *SlackNotifier {
url := "https://hooks.slack.com/services/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"
Copy link
Member

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)

Copy link
Member

@bobheadxi bobheadxi Feb 24, 2019

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())

daemon/inertiad/project/deployment.go Outdated Show resolved Hide resolved
daemon/inertiad/project/deployment_test.go Outdated Show resolved Hide resolved
@bobheadxi bobheadxi added the pr: wip in progress but seeking feedback label Feb 24, 2019
Copy link
Member

@yaoharry yaoharry left a 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.

@terryz21
Copy link
Contributor Author

terryz21 commented Feb 26, 2019

Thanks for the comments! I will make these changes along with some of the formatting additions this week

@codecov
Copy link

codecov bot commented Mar 30, 2019

Codecov Report

Merging #585 into master will decrease coverage by 0.08%.
The diff coverage is 25%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
daemon/inertiad/project/deployment.go 33.79% <25%> (-0.33%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1f592bb...7684d68. Read the comment docs.


// Notify sends the notification
func (n *SlackNotifier) Notify(text string, options *NotifyOptions) error {
// check if url is empty
Copy link
Member

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 😋

Suggested change
// check if url is empty
// check if url is empty

return err
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should check error here

bodyString := string(body)

if resp.StatusCode < 200 || resp.StatusCode > 299 {
return errors.New("Http request rejected by Slack. Error: " + bodyString)
Copy link
Member

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:

Suggested change
return errors.New("Http request rejected by Slack. Error: " + bodyString)
return errors.New("http request rejected by Slack. Error: " + bodyString)

Copy link
Member

@bobheadxi bobheadxi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

almost there 😁

@bobheadxi bobheadxi self-assigned this Oct 2, 2019
@bobheadxi bobheadxi removed the pr: wip in progress but seeking feedback label Oct 2, 2019
@bobheadxi bobheadxi added the pr: finalized needs review and final approval label Oct 2, 2019
@bobheadxi
Copy link
Member

We've been flagged for abuse again, so travis builds aren't running... ugh

image

@bobheadxi bobheadxi merged commit 13389b4 into master Oct 3, 2019
@bobheadxi bobheadxi deleted the daemon/#281-slack-notifier branch October 3, 2019 21:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr: finalized needs review and final approval
Projects
None yet
Development

Successfully merging this pull request may close these issues.

daemon: slack integration
3 participants