-
Notifications
You must be signed in to change notification settings - Fork 170
MM-68829 Improving UX for DMs sent on PR comments #1010
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -287,6 +287,8 @@ func (p *Plugin) handleWebhook(w http.ResponseWriter, r *http.Request) { | |
| repo = event.GetRepo() | ||
| handler = func() { | ||
| p.postPullRequestReviewCommentEvent(event) | ||
| p.handleReviewCommentMentionNotification(event) | ||
| p.handleReviewCommentAuthorNotification(event) | ||
| } | ||
| case *github.PushEvent: | ||
| repo = ConvertPushEventRepositoryToRepository(event.GetRepo()) | ||
|
|
@@ -1019,12 +1021,16 @@ func (p *Plugin) postPullRequestReviewEvent(event *github.PullRequestReviewEvent | |
| func (p *Plugin) postPullRequestReviewCommentEvent(event *github.PullRequestReviewCommentEvent) { | ||
| repo := event.GetRepo() | ||
|
|
||
| if event.GetAction() != actionCreated { | ||
| return | ||
| } | ||
|
|
||
| subs := p.GetSubscribedChannelsForRepository(repo) | ||
| if len(subs) == 0 { | ||
| return | ||
| } | ||
|
|
||
| newReviewMessage, err := renderTemplate("newReviewComment", event) | ||
| message, err := renderTemplate("newReviewComment", event) | ||
| if err != nil { | ||
| p.client.Log.Warn("Failed to render template", "error", err.Error()) | ||
| return | ||
|
|
@@ -1061,7 +1067,7 @@ func (p *Plugin) postPullRequestReviewCommentEvent(event *github.PullRequestRevi | |
| continue | ||
| } | ||
|
|
||
| post := p.makeBotPost(newReviewMessage, "custom_git_pr_comment") | ||
| post := p.makeBotPost(message, "custom_git_pr_comment") | ||
|
|
||
| repoName := strings.ToLower(repo.GetFullName()) | ||
| commentID := event.GetComment().GetID() | ||
|
|
@@ -1077,6 +1083,95 @@ func (p *Plugin) postPullRequestReviewCommentEvent(event *github.PullRequestRevi | |
| } | ||
| } | ||
|
|
||
| func (p *Plugin) handleReviewCommentMentionNotification(event *github.PullRequestReviewCommentEvent) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. handleCommentMentionNotification filters out mentioned users who are also assignees. Maybe worth mirroring the skip logic for consistency and to avoid double DM?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For the |
||
| if event.GetAction() != actionCreated { | ||
| return | ||
| } | ||
|
|
||
| body := event.GetComment().GetBody() | ||
|
|
||
| if strings.Contains(body, "notifications@github.com") { | ||
| body = strings.Split(body, "\n\nOn")[0] | ||
| } | ||
|
|
||
| mentionedUsernames := parseGitHubUsernamesFromText(body) | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| message, err := renderTemplate("reviewCommentMentionNotification", event) | ||
| if err != nil { | ||
| p.client.Log.Warn("Failed to render template", "error", err.Error()) | ||
| return | ||
| } | ||
|
|
||
| for _, username := range mentionedUsernames { | ||
| if username == event.GetSender().GetLogin() { | ||
| continue | ||
| } | ||
|
|
||
| if username == event.GetPullRequest().GetUser().GetLogin() { | ||
| continue | ||
|
coderabbitai[bot] marked this conversation as resolved.
Outdated
|
||
| } | ||
|
|
||
| userID := p.getGitHubToUserIDMapping(username) | ||
| if userID == "" { | ||
| continue | ||
| } | ||
|
|
||
| if event.GetRepo().GetPrivate() && !p.permissionToRepo(userID, event.GetRepo().GetFullName()) { | ||
| continue | ||
| } | ||
|
|
||
| if p.senderMutedByReceiver(userID, event.GetSender().GetLogin()) { | ||
| continue | ||
| } | ||
|
|
||
| channel, err := p.client.Channel.GetDirect(userID, p.BotUserID) | ||
| if err != nil { | ||
| continue | ||
| } | ||
|
|
||
| post := p.makeBotPost(message, "custom_git_mention") | ||
| post.ChannelId = channel.Id | ||
| if err = p.client.Post.CreatePost(post); err != nil { | ||
| p.client.Log.Warn("Error creating review comment mention post", "error", err.Error()) | ||
| } | ||
|
|
||
| p.sendRefreshEvent(userID) | ||
| } | ||
| } | ||
|
|
||
| func (p *Plugin) handleReviewCommentAuthorNotification(event *github.PullRequestReviewCommentEvent) { | ||
| author := event.GetPullRequest().GetUser().GetLogin() | ||
| if author == event.GetSender().GetLogin() { | ||
| return | ||
| } | ||
|
|
||
| if event.GetAction() != actionCreated { | ||
| return | ||
| } | ||
|
|
||
| authorUserID := p.getGitHubToUserIDMapping(author) | ||
| if authorUserID == "" { | ||
| return | ||
| } | ||
|
|
||
| if event.GetRepo().GetPrivate() && !p.permissionToRepo(authorUserID, event.GetRepo().GetFullName()) { | ||
| return | ||
| } | ||
|
|
||
| if p.senderMutedByReceiver(authorUserID, event.GetSender().GetLogin()) { | ||
| return | ||
| } | ||
|
|
||
| message, err := renderTemplate("reviewCommentAuthorNotification", event) | ||
| if err != nil { | ||
| p.client.Log.Warn("Failed to render template", "error", err.Error()) | ||
| return | ||
| } | ||
|
|
||
| p.CreateBotDMPost(authorUserID, message, "custom_git_author") | ||
| p.sendRefreshEvent(authorUserID) | ||
| } | ||
|
|
||
| func (p *Plugin) handleCommentMentionNotification(event *github.IssueCommentEvent) { | ||
| action := event.GetAction() | ||
| if action == actionEdited || action == actionDeleted { | ||
|
|
@@ -1205,6 +1300,11 @@ func (p *Plugin) handleCommentAuthorNotification(event *github.IssueCommentEvent | |
| } | ||
|
|
||
| func (p *Plugin) handleCommentAssigneeNotification(event *github.IssueCommentEvent) { | ||
| action := event.GetAction() | ||
| if action == actionEdited || action == actionDeleted { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can check if handleCommentAssigneeNotification caller already filters out edit and delete actions. If yes this guard is dead code.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The caller ( I'm wondering if we want to move the guard up to |
||
| return | ||
| } | ||
|
|
||
| author := event.GetIssue().GetUser().GetLogin() | ||
| assignees := event.GetIssue().Assignees | ||
| repoName := event.GetRepo().GetFullName() | ||
|
|
||
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.
nit: this if cleaned == "" { return "" } block returns "" either way. Just return cleaned