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

Add ability to send notifications to slack #531

Merged
merged 3 commits into from
Jul 27, 2020
Merged

Add ability to send notifications to slack #531

merged 3 commits into from
Jul 27, 2020

Conversation

nghialv
Copy link
Member

@nghialv nghialv commented Jul 27, 2020

What this PR does / why we need it:

Which issue(s) this PR fixes:

Fixes #

Does this PR introduce a user-facing change?:

NONE

/cc @nakabonne

@pipecd-bot
Copy link
Collaborator

GO_LINTER

The following files are not gofmt-ed. By commenting /golinter fmt, the formatted one will be appended to this pull request automatically.

pkg/app/piped/notifier/slack.go
--- pkg/app/piped/notifier/slack.go.orig
+++ pkg/app/piped/notifier/slack.go
@@ -213,7 +213,7 @@
 func makeSlackMessage(title, titleLink, text, color string, timestamp int64, fields ...slackField) slackMessage {
 	return slackMessage{
 		Username: slackUsername,
-		Attachments: []slackAttachment{slackAttachment{
+		Attachments: []slackAttachment{{
 			Title:     title,
 			TitleLink: titleLink,
 			Text:      text,

Copy link
Collaborator

@pipecd-bot pipecd-bot left a comment

Choose a reason for hiding this comment

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

GO_LINTER

Some issues were detected while linting go source files in your changes.

pkg/app/piped/notifier/slack.go Show resolved Hide resolved
@pipecd-bot
Copy link
Collaborator

COVERAGE

Code coverage for golang is 20.86%. This pull request decreases coverage by -0.27%.

File Function Base Head Diff
pkg/app/piped/notifier/slack.go buildSlackMessage -- 0.00% +0.00%
pkg/app/piped/notifier/slack.go makeSlackLink -- 0.00% +0.00%
pkg/app/piped/notifier/slack.go makeSlackDate -- 0.00% +0.00%
pkg/app/piped/notifier/slack.go truncateText -- 0.00% +0.00%
pkg/app/piped/notifier/slack.go makeSlackMessage -- 0.00% +0.00%
pkg/app/piped/notifier/slack.go slack.sendMessage -- 0.00% +0.00%
pkg/model/deployment.go Deployment.TriggeredBy -- 0.00% +0.00%
pkg/model/event.go EventDeploymentTriggered.AppName -- 100.00% +100.00%
pkg/model/event.go EventDeploymentPlanned.AppName -- 0.00% +0.00%
pkg/model/event.go EventDeploymentApproved.AppName -- 0.00% +0.00%
pkg/model/event.go EventDeploymentRollingBack.AppName -- 0.00% +0.00%
pkg/model/event.go EventDeploymentSucceeded.AppName -- 0.00% +0.00%
pkg/model/event.go EventDeploymentFailed.AppName -- 0.00% +0.00%
pkg/model/event.go EventApplicationSynced.AppName -- 0.00% +0.00%
pkg/model/event.go EventApplicationOutOfSync.AppName -- 0.00% +0.00%
pkg/app/piped/notifier/slack.go slack.Run 0.00% 0.00% +0.00%
pkg/app/piped/notifier/slack.go slack.Notify 100.00% 0.00% +0.00%
pkg/model/event.go EventDeploymentTriggered.AppID 100.00% -- -100.00%
pkg/model/event.go EventDeploymentPlanned.AppID 0.00% -- +-0.00%
pkg/model/event.go EventDeploymentApproved.AppID 0.00% -- +-0.00%
pkg/model/event.go EventDeploymentRollingBack.AppID 0.00% -- +-0.00%
pkg/model/event.go EventDeploymentSucceeded.AppID 0.00% -- +-0.00%
pkg/model/event.go EventDeploymentFailed.AppID 0.00% -- +-0.00%
pkg/model/event.go EventApplicationSynced.AppID 0.00% -- +-0.00%
pkg/model/event.go EventApplicationOutOfSync.AppID 0.00% -- +-0.00%

@pipecd-bot
Copy link
Collaborator

COVERAGE

Code coverage for golang is 20.86%. This pull request decreases coverage by -0.27%.

File Function Base Head Diff
pkg/app/piped/notifier/slack.go buildSlackMessage -- 0.00% +0.00%
pkg/app/piped/notifier/slack.go makeSlackLink -- 0.00% +0.00%
pkg/app/piped/notifier/slack.go makeSlackDate -- 0.00% +0.00%
pkg/app/piped/notifier/slack.go truncateText -- 0.00% +0.00%
pkg/app/piped/notifier/slack.go makeSlackMessage -- 0.00% +0.00%
pkg/app/piped/notifier/slack.go slack.sendMessage -- 0.00% +0.00%
pkg/model/deployment.go Deployment.TriggeredBy -- 0.00% +0.00%
pkg/model/event.go EventDeploymentTriggered.AppName -- 100.00% +100.00%
pkg/model/event.go EventDeploymentPlanned.AppName -- 0.00% +0.00%
pkg/model/event.go EventDeploymentApproved.AppName -- 0.00% +0.00%
pkg/model/event.go EventDeploymentRollingBack.AppName -- 0.00% +0.00%
pkg/model/event.go EventDeploymentSucceeded.AppName -- 0.00% +0.00%
pkg/model/event.go EventDeploymentFailed.AppName -- 0.00% +0.00%
pkg/model/event.go EventApplicationSynced.AppName -- 0.00% +0.00%
pkg/model/event.go EventApplicationOutOfSync.AppName -- 0.00% +0.00%
pkg/app/piped/notifier/slack.go slack.Notify 100.00% 0.00% +0.00%
pkg/app/piped/notifier/slack.go slack.Run 0.00% 0.00% +0.00%
pkg/model/event.go EventDeploymentTriggered.AppID 100.00% -- -100.00%
pkg/model/event.go EventDeploymentPlanned.AppID 0.00% -- +-0.00%
pkg/model/event.go EventDeploymentApproved.AppID 0.00% -- +-0.00%
pkg/model/event.go EventDeploymentRollingBack.AppID 0.00% -- +-0.00%
pkg/model/event.go EventDeploymentSucceeded.AppID 0.00% -- +-0.00%
pkg/model/event.go EventDeploymentFailed.AppID 0.00% -- +-0.00%
pkg/model/event.go EventApplicationSynced.AppID 0.00% -- +-0.00%
pkg/model/event.go EventApplicationOutOfSync.AppID 0.00% -- +-0.00%

md := event.Metadata.(*model.EventDeploymentTriggered)
title = fmt.Sprintf("Triggered a new deployment for %q", md.Deployment.ApplicationName)
generateDeploymentEventData(md.Deployment)
break
Copy link
Member

Choose a reason for hiding this comment

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

What are these break statements for?

Copy link
Member Author

Choose a reason for hiding this comment

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

lol. Removed them.

@pipecd-bot
Copy link
Collaborator

TODO

The following ISSUES will be created once got merged. If you want me to skip creating the issue, you can use /todo skip command.

Details

1. Send all remaining events before exiting.

https://github.com/pipe-cd/pipe/blob/c3c85176829e443898d65a62552eda8f8a0b786c/pkg/app/piped/notifier/slack.go#L83-L86

This was created by todo plugin since "TODO:" was found in c3c8517 when #531 was merged. cc: @nghialv.

2. Use environment name instead of id.

https://github.com/pipe-cd/pipe/blob/c3c85176829e443898d65a62552eda8f8a0b786c/pkg/app/piped/notifier/slack.go#L103-L106

This was created by todo plugin since "TODO:" was found in c3c8517 when #531 was merged. cc: @nghialv.

@pipecd-bot
Copy link
Collaborator

COVERAGE

Code coverage for golang is 20.89%. This pull request decreases coverage by -0.25%.

File Function Base Head Diff
pkg/app/piped/notifier/slack.go buildSlackMessage -- 0.00% +0.00%
pkg/app/piped/notifier/slack.go makeSlackLink -- 0.00% +0.00%
pkg/app/piped/notifier/slack.go makeSlackDate -- 0.00% +0.00%
pkg/app/piped/notifier/slack.go truncateText -- 0.00% +0.00%
pkg/app/piped/notifier/slack.go makeSlackMessage -- 0.00% +0.00%
pkg/app/piped/notifier/slack.go slack.sendMessage -- 0.00% +0.00%
pkg/model/deployment.go Deployment.TriggeredBy -- 0.00% +0.00%
pkg/model/event.go EventDeploymentTriggered.AppName -- 100.00% +100.00%
pkg/model/event.go EventDeploymentPlanned.AppName -- 0.00% +0.00%
pkg/model/event.go EventDeploymentApproved.AppName -- 0.00% +0.00%
pkg/model/event.go EventDeploymentRollingBack.AppName -- 0.00% +0.00%
pkg/model/event.go EventDeploymentSucceeded.AppName -- 0.00% +0.00%
pkg/model/event.go EventDeploymentFailed.AppName -- 0.00% +0.00%
pkg/model/event.go EventApplicationSynced.AppName -- 0.00% +0.00%
pkg/model/event.go EventApplicationOutOfSync.AppName -- 0.00% +0.00%
pkg/app/piped/notifier/slack.go slack.Run 0.00% 0.00% +0.00%
pkg/app/piped/notifier/slack.go slack.Notify 100.00% 0.00% +0.00%
pkg/model/event.go EventDeploymentTriggered.AppID 100.00% -- -100.00%
pkg/model/event.go EventDeploymentPlanned.AppID 0.00% -- +-0.00%
pkg/model/event.go EventDeploymentApproved.AppID 0.00% -- +-0.00%
pkg/model/event.go EventDeploymentRollingBack.AppID 0.00% -- +-0.00%
pkg/model/event.go EventDeploymentSucceeded.AppID 0.00% -- +-0.00%
pkg/model/event.go EventDeploymentFailed.AppID 0.00% -- +-0.00%
pkg/model/event.go EventApplicationSynced.AppID 0.00% -- +-0.00%
pkg/model/event.go EventApplicationOutOfSync.AppID 0.00% -- +-0.00%

}
}

switch event.Type {
Copy link
Member

Choose a reason for hiding this comment

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

Just in case, let me confirm that you didn't include intentionally some EventTypes such as EventType_EVENT_APPLICATION_SYNCED etc...

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes. Let me add a TODO for them in the next PR.

Copy link
Member

Choose a reason for hiding this comment

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

👍

Copy link
Member

Choose a reason for hiding this comment

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

Oh, you said adding in the next PR.

@nakabonne
Copy link
Member

/approve

@pipecd-bot
Copy link
Collaborator

APPROVE

This pull request is APPROVED by nakabonne.

Approvers can cancel the approval by writing /approve cancel in a comment. Any additional commits also will change this pull request to be not-approved.

@pipecd-bot pipecd-bot merged commit c61f4ef into master Jul 27, 2020
@pipecd-bot pipecd-bot deleted the notification branch July 27, 2020 09:17
@pipecd-bot
Copy link
Collaborator

TEMPLATE

failed to handle template rule examples

Details
Error: unabled to push rendered files to destination

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants