-
Notifications
You must be signed in to change notification settings - Fork 135
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
base: master
Are you sure you want to change the base?
Conversation
pkg/model/notificationevent.pb.go
Outdated
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.
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.
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.
Thanks @t-kikuc i reverted the change notificationevent.pb.go
and successfully ran make gen/code
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.
@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>
8f64f00
to
868baa8
Compare
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.
Thank you for your great contribution!
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.
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
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.
It seems you need to copy the changes of notifier/slack.go
& slack_test.go
to piped/notifier/
🙇
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.
yes, done
pkg/app/pipedv1/notifier/slack.go
Outdated
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)) |
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.
You mean this??
generateDeploymentEventData(md.Deployment, getAccountsAsString(md.MentionedAccounts), getAccountsAsString(md.MentionedGroups)) | |
generateDeploymentEventData(md.Deployment, getAccountsAsString(md.MentionedAccounts), getGroupsAsString(md.MentionedGroups)) |
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.
sorry a typo, fixed
pkg/app/pipedv1/notifier/slack.go
Outdated
@@ -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) { |
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.
[IMO]
How about calling getAccountsAsString(), getGroupsAsString() here to simplify the switch part?
generateDeploymentEventData := func(d *model.Deployment, accounts string, groups string) { | |
generateDeploymentEventData := func(d *model.Deployment, accounts, groups []string) { | |
accountsStr := getAccountsAsString(accounts) | |
groupsStr := getGroupsAsString(groups) |
pkg/app/pipedv1/notifier/slack.go
Outdated
{"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) { |
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.
[IMO]
How about calling getAccountsAsString(), getGroupsAsString() here to simplify the switch part?
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) |
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.
@t-kikuc thank you, yes, calling that way should be visible!
pkg/config/piped.go
Outdated
mentionedGroups := make([]string, 0, len(n.MentionedGroups)) | ||
for _, mentionedGroup := range n.MentionedGroups { | ||
formatMentionedGroup := fmt.Sprintf("<!subteam^%s>", strings.TrimPrefix(mentionedGroup, "@")) | ||
mentionedGroups = append(mentionedGroups, formatMentionedGroup) | ||
} |
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.
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. :)
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.
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?
Ping @minhquang4334 👋 |
- '@user2' | ||
mentionedGroups: | ||
- 'group1' | ||
- '@group2' |
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.
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.
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.
@minhquang4334 thank you very much for your support, yes I agreed with your point
so should be support both <!subteam^ID>
or only ID
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.
@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 :)
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.
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>
…ange Signed-off-by: hungran <26101787+hungran@users.noreply.github.com>
- 'group1' | ||
- '<!subteam^group2>' |
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.
Using the groupID or teamID in the documents makes it easier for users to use this feature.
- 'group1' | |
- '<!subteam^group2>' | |
- 'groupID1' | |
- '<!subteam^groupID2>' |
- '@user2' | ||
mentionedGroups: | ||
- 'group1' | ||
- '@group2' |
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.
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 { |
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.
It would be better if we changed Slack
to SlackUsers
to separate it from SlackGroups
.
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.
@minhquang4334 thanks, will have a look
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 andslackGroups
for NotificationMentionWhich issue(s) this PR fixes:
Fixes #4730
Does this PR introduce a user-facing change?: N/A