MM-67256 Adding support for MR assigned/unassigned messages in subscriptions#651
MM-67256 Adding support for MR assigned/unassigned messages in subscriptions#651avasconcelos114 wants to merge 5 commits intomasterfrom
Conversation
|
@coderabbitai please review this PR |
|
✅ Actions performedReview triggered.
|
📝 WalkthroughWalkthroughThis pull request introduces a new notification feature for merge request assignment and unassignment events. The implementation includes documentation, CLI support, a feature flag with accessor, webhook event handling logic with channel filtering, and comprehensive test coverage across multiple files. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~30 minutes 🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
server/webhook/webhook.go (1)
152-174: Inconsistent error handling for label retrieval compared toanyEventLabelInSubs.When
sub.Labels()returns an error, this function appends a warning but still includes the channel in the result (execution continues to line 171). However,anyEventLabelInSubs(lines 176-186) returnsfalseon error, effectively excluding the channel.This inconsistency could lead to unexpected behaviour where channels with malformed label subscriptions are included by
filterChannelsByFeaturebut excluded byanyEventLabelInSubs.Consider adding a
continueafter appending the warning to match the existing behaviour:♻️ Proposed fix for consistent error handling
labels, err := sub.Labels() if err != nil { warnings = append(warnings, err.Error()) + continue } else if len(labels) > 0 && !containsAnyLabel(eventLabels, labels) { continue }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@server/webhook/webhook.go` around lines 152 - 174, filterChannelsByFeature currently appends a warning when sub.Labels() errors but continues and includes sub.ChannelID, which is inconsistent with anyEventLabelInSubs that excludes channels on label errors; update filterChannelsByFeature (the loop in filterChannelsByFeature calling sub.Labels()) to continue the loop immediately after appending the warning (i.e., skip adding sub.ChannelID on error) so behavior matches anyEventLabelInSubs and malformed label subscriptions are excluded.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@server/webhook/webhook.go`:
- Around line 152-174: filterChannelsByFeature currently appends a warning when
sub.Labels() errors but continues and includes sub.ChannelID, which is
inconsistent with anyEventLabelInSubs that excludes channels on label errors;
update filterChannelsByFeature (the loop in filterChannelsByFeature calling
sub.Labels()) to continue the loop immediately after appending the warning
(i.e., skip adding sub.ChannelID on error) so behavior matches
anyEventLabelInSubs and malformed label subscriptions are excluded.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 24104402-39dc-452a-945e-fb39df791837
📒 Files selected for processing (7)
README.mdserver/command.goserver/subscription/subscription.goserver/webhook/merge_request.goserver/webhook/merge_request_fixture_test.goserver/webhook/merge_request_test.goserver/webhook/webhook.go
| if err != nil { | ||
| warnings = append(warnings, err.Error()) | ||
| } else if len(labels) > 0 && !containsAnyLabel(eventLabels, labels) { | ||
| continue | ||
| } | ||
|
|
||
| channels = append(channels, sub.ChannelID) |
There was a problem hiding this comment.
It seems that when there is an error we store the warning message but still add the channel to the filtered list. Is that intended?
There was a problem hiding this comment.
Ah this is a bit of pre-existing logic that was ported over to be applied here too, the original snippet takes a pretty lenient approach where it virtually treats this error as human error in the part of the user (in https://github.com/mattermost/mattermost-plugin-gitlab/blob/master/server/webhook/issue.go#L110) and still appends the channel ID to the list (the error happens if a user formats the label as label:bug instead of label:"bug")
We could change our approach to be stricter though that would likely mean changing the pre-existing behavior of the issue handler too (or we could add the validation that #603 alludes to be missing where it would prevent malformed or inexistent labels from being accepted by subscriptions to begin with -- though this would be out of scope for this PR)
| if len(assignMessages) > 0 { | ||
| toChannels, ws := filterChannelsByFeature(subs, event.Labels, func(sub *subscription.Subscription) bool { |
There was a problem hiding this comment.
Will existing channel subscriptions start to get the notifications for assigned/unassiged?
There was a problem hiding this comment.
Yes, from what I could understand the merges subscription pertains to anything related to merge requests, so these events will automatically kick-in for subscriptions made at that level, and the new merge_request_assigns is a more granular event added in case users would like to individually select these events to be included in a subscription
Summary
This PR adds the handling necessary for users to subscribe to merge request assigned/unassigned events
Ticket Link
Fixes https://mattermost.atlassian.net/browse/MM-67256
Summary by CodeRabbit
Release Notes
New Features
Documentation