Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions server/plugin/test_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,12 @@ func GetMockPullRequestReviewCommentEvent(action, body, sender string) *github.P
}
}

func GetMockPullRequestReviewCommentReplyEvent(action, body, sender string, replyTo int64) *github.PullRequestReviewCommentEvent {
event := GetMockPullRequestReviewCommentEvent(action, body, sender)
event.Comment.InReplyTo = github.Int64(replyTo)
return event
}

func GetMockIssueCommentEvent(action, body, sender string) *github.IssueCommentEvent {
return &github.IssueCommentEvent{
Action: github.String(action),
Expand Down
5 changes: 5 additions & 0 deletions server/plugin/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -1151,6 +1151,11 @@ func (p *Plugin) handleReviewCommentAuthorNotification(event *github.PullRequest
return
}

// Top-level comments on a submitted review are already DMed via handlePullRequestReviewNotification.
if event.GetComment().GetInReplyTo() == 0 {
return
}

authorUserID := p.getGitHubToUserIDMapping(author)
if authorUserID == "" {
return
Expand Down
15 changes: 10 additions & 5 deletions server/plugin/webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -611,12 +611,17 @@ func TestHandleReviewCommentAuthorNotification(t *testing.T) {
},
{
name: "Sender is the PR author",
event: GetMockPullRequestReviewCommentEvent(actionCreated, "body", MockIssueAuthor),
event: GetMockPullRequestReviewCommentReplyEvent(actionCreated, "body", MockIssueAuthor, 99),
setup: func(_ *plugintest.API, _ *mocks.MockKvStore) {},
},
{
name: "Author not mapped to Mattermost",
name: "Top-level review comment is covered by the review submitted notification",
event: GetMockPullRequestReviewCommentEvent(actionCreated, "body", MockUserLogin),
setup: func(_ *plugintest.API, _ *mocks.MockKvStore) {},
},
{
name: "Author not mapped to Mattermost",
event: GetMockPullRequestReviewCommentReplyEvent(actionCreated, "body", MockUserLogin, 99),
setup: func(_ *plugintest.API, mockKVStore *mocks.MockKvStore) {
mockKVStore.EXPECT().Get("issueAuthor_githubusername", mock.MatchedBy(func(val any) bool {
_, ok := val.(*[]uint8)
Expand All @@ -625,8 +630,8 @@ func TestHandleReviewCommentAuthorNotification(t *testing.T) {
},
},
{
name: "Successful author notification",
event: GetMockPullRequestReviewCommentEvent(actionCreated, "body", MockUserLogin),
name: "Successful author notification for thread reply",
event: GetMockPullRequestReviewCommentReplyEvent(actionCreated, "body", MockUserLogin, 99),
setup: func(mockAPI *plugintest.API, mockKVStore *mocks.MockKvStore) {
mockKVStore.EXPECT().Get("issueAuthor_githubusername", mock.MatchedBy(func(val any) bool {
_, ok := val.(*[]uint8)
Expand All @@ -646,7 +651,7 @@ func TestHandleReviewCommentAuthorNotification(t *testing.T) {
},
{
name: "Muted sender suppresses author notification",
event: GetMockPullRequestReviewCommentEvent(actionCreated, "body", MockUserLogin),
event: GetMockPullRequestReviewCommentReplyEvent(actionCreated, "body", MockUserLogin, 99),
setup: func(_ *plugintest.API, mockKVStore *mocks.MockKvStore) {
mockKVStore.EXPECT().Get("issueAuthor_githubusername", mock.MatchedBy(func(val any) bool {
_, ok := val.(*[]uint8)
Expand Down
Loading