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

feat: add support mention slack groups for NotificationReceiverSlack and NotificationMention #4903

Open
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

hungran
Copy link
Contributor

@hungran hungran commented Apr 30, 2024

What this PR does / why we need it:
as mentioned from the issue #4730, currently PipeCD pipeCD is supporting individual user mention

According on difference syntax that slack support mention in message

This PR will have feature to add field mentionedGroups for NotificationReceiverSlack and slackGroups for NotificationMention

Which issue(s) this PR fixes:

Fixes #4730

Does this PR introduce a user-facing change?: N/A

  • How are users affected by this change: N/A
  • Is this breaking change: N/A
  • How to migrate (if breaking change): N/A

@hungran hungran changed the title feat: add support mention slack groups for NotifactionReceiverSlack and NotificationMention feat: add support mention slack groups for NotificationReceiverSlack and NotificationMention Apr 30, 2024
Copy link
Member

Choose a reason for hiding this comment

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

As the comment in the file says as following,

// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// 	protoc-gen-go v1.27.1
// 	protoc        v3.18.1
// source: pkg/model/notificationevent.proto

you need to edit notificationevent.proto instead and run make gen/code to generate protobuf files.

Copy link
Contributor Author

@hungran hungran May 1, 2024

Choose a reason for hiding this comment

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

Thanks @t-kikuc i reverted the change notificationevent.pb.go and successfully ran make gen/code

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@t-kikuc
correct me if im wrong
instead change notificationevent.pb.go, we add field at pkg/model/notificationevent.proto ?

…ackGroups for NotificationMention

Signed-off-by: hungran <26101787+hungran@users.noreply.github.com>
Copy link
Member

@t-kikuc t-kikuc left a comment

Choose a reason for hiding this comment

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

Thank you for your great contribution!

Copy link
Member

Choose a reason for hiding this comment

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

These changes should be removed.

  • docs/content/en/docs-v0.47.x/user-guide/configuration-reference.md
  • docs/content/en/docs-v0.47.x/user-guide/managing-piped/configuration-reference.md
  • docs/content/en/docs-v0.47.x/user-guide/managing-piped/configuring-notifications.md

That's because this feature would be released in v0.48.0 or v0.48.0-rcX, not v0.47.x

Copy link
Member

Choose a reason for hiding this comment

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

It seems you need to copy the changes of notifier/slack.go & slack_test.go to piped/notifier/ 🙇

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, done

title = fmt.Sprintf("Deployment for %q was planned", md.Deployment.ApplicationName)
text = md.Summary
generateDeploymentEventData(md.Deployment, getAccountsAsString(md.MentionedAccounts))
generateDeploymentEventData(md.Deployment, getAccountsAsString(md.MentionedAccounts), getAccountsAsString(md.MentionedGroups))
Copy link
Member

Choose a reason for hiding this comment

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

You mean this??

Suggested change
generateDeploymentEventData(md.Deployment, getAccountsAsString(md.MentionedAccounts), getAccountsAsString(md.MentionedGroups))
generateDeploymentEventData(md.Deployment, getAccountsAsString(md.MentionedAccounts), getGroupsAsString(md.MentionedGroups))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sorry a typo, fixed

@@ -205,20 +205,21 @@ func (s *slack) buildSlackMessage(event model.NotificationEvent, webURL string)
fields []slackField
)

generateDeploymentEventData := func(d *model.Deployment, accounts string) {
generateDeploymentEventData := func(d *model.Deployment, accounts string, groups string) {
Copy link
Member

Choose a reason for hiding this comment

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

[IMO]
How about calling getAccountsAsString(), getGroupsAsString() here to simplify the switch part?

Suggested change
generateDeploymentEventData := func(d *model.Deployment, accounts string, groups string) {
generateDeploymentEventData := func(d *model.Deployment, accounts, groups []string) {
accountsStr := getAccountsAsString(accounts)
groupsStr := getGroupsAsString(groups)

{"Started At", makeSlackDate(d.CreatedAt), true},
}
}

generateDeploymentEventDataForTriggerFailed := func(app *model.Application, hash, msg, accounts string) {
generateDeploymentEventDataForTriggerFailed := func(app *model.Application, hash, msg, accounts string, groups string) {
Copy link
Member

Choose a reason for hiding this comment

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

[IMO]
How about calling getAccountsAsString(), getGroupsAsString() here to simplify the switch part?

Suggested change
generateDeploymentEventDataForTriggerFailed := func(app *model.Application, hash, msg, accounts string, groups string) {
generateDeploymentEventDataForTriggerFailed := func(app *model.Application, hash, msg string, accounts, groups []string) {
accountsStr := getAccountsAsString(accounts)
groupsStr := getGroupsAsString(groups)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@t-kikuc thank you, yes, calling that way should be visible!

Comment on lines 975 to 979
mentionedGroups := make([]string, 0, len(n.MentionedGroups))
for _, mentionedGroup := range n.MentionedGroups {
formatMentionedGroup := fmt.Sprintf("<!subteam^%s>", strings.TrimPrefix(mentionedGroup, "@"))
mentionedGroups = append(mentionedGroups, formatMentionedGroup)
}
Copy link
Member

Choose a reason for hiding this comment

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

Is this logic necessary here? It seems also in the func getGroupsAsString 👀
If possible, it would be nice to put it in the getGroupsAsString because this func is just for validating. :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

um not sure but i've seen we already have same thing for user

	mentionedAccounts := make([]string, 0, len(n.MentionedAccounts))
	for _, mentionedAccount := range n.MentionedAccounts {
		formatMentionedAccount := strings.TrimPrefix(mentionedAccount, "@")
		mentionedAccounts = append(mentionedAccounts, formatMentionedAccount)
	}

should we already remove it as well because getAccountsAsString already have it?

@khanhtc1202
Copy link
Member

Ping @minhquang4334 👋

- '@user2'
mentionedGroups:
- 'group1'
- '@group2'
Copy link
Contributor

Choose a reason for hiding this comment

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

IMO, we should not use "@" to mention a slack group because the handle field after '@' (eg. group2) is mutable, it is not convenient since changing the handle involves updating configuration.
refs: https://slack.com/help/articles/212906697-Create-a-user-group

Thus, I suggest using <!subteam^ID> for group mentioning, since the fields are immutable and can be used according to Slack's official docs.

Copy link
Contributor Author

@hungran hungran May 11, 2024

Choose a reason for hiding this comment

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

@minhquang4334 thank you very much for your support, yes I agreed with your point
so should be support both <!subteam^ID> or only ID

Copy link
Contributor Author

@hungran hungran May 11, 2024

Choose a reason for hiding this comment

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

@minhquang4334 just from the time being, as slack's client, using slack to mention user and group has exactly same way (by @) so as i understand, this field is for human interactive, we should have same way with Slack UI. Just though

btw, i followed your idea :)

Copy link
Contributor

Choose a reason for hiding this comment

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

thank you @hungran

Signed-off-by: hungran <26101787+hungran@users.noreply.github.com>
Signed-off-by: hungran <26101787+hungran@users.noreply.github.com>
Signed-off-by: hungran <26101787+hungran@users.noreply.github.com>
Signed-off-by: hungran <26101787+hungran@users.noreply.github.com>
Signed-off-by: hungran <26101787+hungran@users.noreply.github.com>
Signed-off-by: hungran <26101787+hungran@users.noreply.github.com>
Signed-off-by: hungran <26101787+hungran@users.noreply.github.com>
Signed-off-by: hungran <26101787+hungran@users.noreply.github.com>
Signed-off-by: hungran <26101787+hungran@users.noreply.github.com>
…ange

Signed-off-by: hungran <26101787+hungran@users.noreply.github.com>
Comment on lines +101 to +102
- 'group1'
- '<!subteam^group2>'
Copy link
Contributor

Choose a reason for hiding this comment

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

Using the groupID or teamID in the documents makes it easier for users to use this feature.

Suggested change
- 'group1'
- '<!subteam^group2>'
- 'groupID1'
- '<!subteam^groupID2>'

- '@user2'
mentionedGroups:
- 'group1'
- '@group2'
Copy link
Contributor

Choose a reason for hiding this comment

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

thank you @hungran

as := make(map[string]struct{})
for _, m := range n.Mentions {
if m.Event != allEventsSymbol && "EVENT_"+m.Event != event.String() {
continue
}
for _, s := range m.Slack {
as[s] = struct{}{}
if len(m.Slack) > 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be better if we changed Slack to SlackUsers to separate it from SlackGroups.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@minhquang4334 thanks, will have a look

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

Successfully merging this pull request may close these issues.

Support group mentions for slack notification
5 participants