Skip to content

daemon: send slack notifications (#281)#585

Merged
bobheadxi merged 15 commits into
masterfrom
daemon/#281-slack-notifier
Oct 3, 2019
Merged

daemon: send slack notifications (#281)#585
bobheadxi merged 15 commits into
masterfrom
daemon/#281-slack-notifier

Conversation

@terryz21

@terryz21 terryz21 commented Feb 24, 2019

Copy link
Copy Markdown
Contributor

🎟️ 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 bobheadxi as a code owner February 24, 2019 11:55
@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

@bobheadxi bobheadxi left a comment

Copy link
Copy Markdown
Member

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!

Comment thread daemon/inertiad/main.go Outdated
Comment thread daemon/inertiad/notifier/notifier.go Outdated
return err
}

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

Copy link
Copy Markdown
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)

Comment thread daemon/inertiad/notifier/notifier.go Outdated
Comment thread 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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"

Copy link
Copy Markdown
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)

@bobheadxi bobheadxi Feb 24, 2019

Copy link
Copy Markdown
Member

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

Comment thread daemon/inertiad/project/deployment.go Outdated
Comment thread daemon/inertiad/project/deployment_test.go Outdated
@bobheadxi bobheadxi requested a review from yaoharry February 24, 2019 20:20
@bobheadxi bobheadxi added the pr: wip in progress but seeking feedback label Feb 24, 2019

@yaoharry yaoharry left a comment

Copy link
Copy Markdown
Member

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

terryz21 commented Feb 26, 2019

Copy link
Copy Markdown
Contributor Author

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

bobheadxi and others added 7 commits February 25, 2019 19:41
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>
@codecov

codecov Bot commented Mar 30, 2019

Copy link
Copy Markdown

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.

Comment thread daemon/inertiad/notifier/notifier.go Outdated

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

Copy link
Copy Markdown
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

Comment thread daemon/inertiad/notifier/notifier.go Outdated
return err
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)

Copy link
Copy Markdown
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

Comment thread 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)

Copy link
Copy Markdown
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)

@bobheadxi bobheadxi left a comment

Copy link
Copy Markdown
Member

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 added pr: finalized needs review and final approval and removed pr: wip in progress but seeking feedback labels Oct 2, 2019
@bobheadxi

Copy link
Copy Markdown
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