Commit 25b31a44 authored by Ravishankar's avatar Ravishankar Committed by Ravishankar

Add notification settings for mwps

Add change log

Remove comments

Fixing the migration

Review comments

Fixing merge conflicts

Change log

Review changes

dummy

Deleting old migrations

Missed changes

Missed changes

Review comments

missed changes

Translation changes

Missing translation
parent c9766e3d
......@@ -49,7 +49,8 @@ class NotificationSetting < ApplicationRecord
:failed_pipeline,
:fixed_pipeline,
:success_pipeline,
:moved_project
:moved_project,
:merge_when_pipeline_succeeds
].freeze
def self.email_events(source = nil)
......
......@@ -665,7 +665,12 @@ class NotificationService
end
def merge_when_pipeline_succeeds(merge_request, current_user)
recipients = ::NotificationRecipients::BuildService.build_recipients(merge_request, current_user, action: 'merge_when_pipeline_succeeds')
recipients = ::NotificationRecipients::BuildService.build_recipients(
merge_request,
current_user,
action: 'merge_when_pipeline_succeeds',
custom_action: :merge_when_pipeline_succeeds
)
recipients.each do |recipient|
mailer.merge_when_pipeline_succeeds_email(recipient.user.id, merge_request.id, current_user.id).deliver_later
......
---
title: Add setting to control merge when pipeline succeeds notification
merge_request: 37880
author: Ravishankar
type: added
# frozen_string_literal: true
# See https://docs.gitlab.com/ee/development/migration_style_guide.html
# for more information on how to write migrations for GitLab.
class AddMergeWhenPipelineSucceedsToNotificationSettings < ActiveRecord::Migration[6.0]
DOWNTIME = false
def change
add_column :notification_settings, :merge_when_pipeline_succeeds, :boolean, default: false, null: false
end
end
4c6061f6ab1cb9e070a3ae87d44caf12d2c110a6033f0b33898b4b7ea7e37055
\ No newline at end of file
......@@ -14530,7 +14530,8 @@ CREATE TABLE notification_settings (
fixed_pipeline boolean,
new_release boolean,
moved_project boolean DEFAULT true NOT NULL,
change_reviewer_merge_request boolean
change_reviewer_merge_request boolean,
merge_when_pipeline_succeeds boolean DEFAULT false NOT NULL
);
CREATE SEQUENCE notification_settings_id_seq
......@@ -39,6 +39,7 @@ If the `custom` level is used, specific email events can be controlled. Availabl
- `fixed_pipeline`
- `success_pipeline`
- `moved_project`
- `merge_when_pipeline_succeeds`
- `new_epic` **(ULTIMATE)**
## Global notification settings
......@@ -94,6 +95,7 @@ curl --request PUT --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab
| `fixed_pipeline` | boolean | no | Enable/disable this notification |
| `success_pipeline` | boolean | no | Enable/disable this notification |
| `moved_project` | boolean | no | Enable/disable this notification ([Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/30371) in GitLab 13.3) |
| `merge_when_pipeline_succeeds` | boolean | no | Enable/disable this notification ([Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/244840) in GitLab 13.9) |
| `new_epic` | boolean | no | Enable/disable this notification ([Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/5863) in GitLab 11.3) **(ULTIMATE)** |
Example response:
......@@ -165,6 +167,7 @@ curl --request PUT --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab
| `fixed_pipeline` | boolean | no | Enable/disable this notification |
| `success_pipeline` | boolean | no | Enable/disable this notification |
| `moved_project` | boolean | no | Enable/disable this notification ([Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/30371) in GitLab 13.3) |
| `merge_when_pipeline_succeeds` | boolean | no | Enable/disable this notification ([Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/244840) in GitLab 13.9) |
| `new_epic` | boolean | no | Enable/disable this notification ([Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/5863) in GitLab 11.3) **(ULTIMATE)** |
Example responses:
......
......@@ -206,7 +206,7 @@ epics:
| Failed pipeline | The author of the pipeline |
| Fixed pipeline ([introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/24309) in GitLab 13.1.) | The author of the pipeline. Enabled by default. |
| Merge merge request | |
| Merge when pipeline succeeds ([introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/211961) in GitLab 13.4) | |
| Merge when pipeline succeeds ([introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/211961) in GitLab 13.4) | Author, Participants, Watchers, Subscribers, and Custom notification level with this event selected. `Note:` Custom notification level is ignored for Author, Watchers and Subscribers |
| New comment | Participants, Watchers, Subscribers, and Custom notification level with this event selected, plus anyone mentioned by `@username` in the comment, with notification level "Mention" or higher |
| New epic | |
| New issue | |
......
......@@ -30,6 +30,7 @@ RSpec.describe NotificationSetting do
:fixed_pipeline,
:success_pipeline,
:moved_project,
:merge_when_pipeline_succeeds,
:new_epic
]
)
......@@ -59,7 +60,8 @@ RSpec.describe NotificationSetting do
:failed_pipeline,
:fixed_pipeline,
:success_pipeline,
:moved_project
:moved_project,
:merge_when_pipeline_succeeds
]
)
end
......@@ -89,6 +91,7 @@ RSpec.describe NotificationSetting do
:fixed_pipeline,
:success_pipeline,
:moved_project,
:merge_when_pipeline_succeeds,
:new_epic
]
)
......
......@@ -20466,6 +20466,9 @@ msgstr ""
msgid "NotificationEvent|Merge merge request"
msgstr ""
msgid "NotificationEvent|Merge when pipeline succeeds"
msgstr ""
msgid "NotificationEvent|Moved project"
msgstr ""
......
......@@ -21,3 +21,4 @@ N_('NotificationEvent|Merge merge request')
N_('NotificationEvent|Failed pipeline')
N_('NotificationEvent|Fixed pipeline')
N_('NotificationEvent|Moved project')
N_('NotificationEvent|Merge when pipeline succeeds')
......@@ -337,6 +337,39 @@ RSpec.describe NotificationRecipient do
expect(recipient.suitable_notification_level?).to eq true
end
end
context 'with merge_when_pipeline_succeeds' do
let(:notification_setting) { user.notification_settings_for(project) }
let(:recipient) do
described_class.new(
user,
:watch,
custom_action: :merge_when_pipeline_succeeds,
target: target,
project: project
)
end
context 'custom event enabled' do
before do
notification_setting.update!(merge_when_pipeline_succeeds: true)
end
it 'returns true' do
expect(recipient.suitable_notification_level?).to eq true
end
end
context 'custom event disabled' do
before do
notification_setting.update!(merge_when_pipeline_succeeds: false)
end
it 'returns false' do
expect(recipient.suitable_notification_level?).to eq false
end
end
end
end
end
......
......@@ -180,7 +180,8 @@ RSpec.describe NotificationSetting do
:failed_pipeline,
:success_pipeline,
:fixed_pipeline,
:moved_project
:moved_project,
:merge_when_pipeline_succeeds
)
end
......
......@@ -2159,8 +2159,38 @@ RSpec.describe NotificationService, :mailer do
end
describe '#merge_when_pipeline_succeeds' do
before do
update_custom_notification(:merge_when_pipeline_succeeds, @u_guest_custom, resource: project)
update_custom_notification(:merge_when_pipeline_succeeds, @u_custom_global)
end
it 'send notification that merge will happen when pipeline succeeds' do
notification.merge_when_pipeline_succeeds(merge_request, assignee)
should_email(merge_request.author)
should_email(@u_watcher)
should_email(@subscriber)
should_email(@u_guest_custom)
should_email(@u_custom_global)
should_not_email(@unsubscriber)
should_not_email(@u_disabled)
end
it 'does not send notification if the custom event is disabled' do
update_custom_notification(:merge_when_pipeline_succeeds, @u_guest_custom, resource: project, value: false)
update_custom_notification(:merge_when_pipeline_succeeds, @u_custom_global, resource: nil, value: false)
notification.merge_when_pipeline_succeeds(merge_request, assignee)
should_not_email(@u_guest_custom)
should_not_email(@u_custom_global)
end
it 'sends notification to participants even if the custom event is disabled' do
update_custom_notification(:merge_when_pipeline_succeeds, merge_request.author, resource: project, value: false)
update_custom_notification(:merge_when_pipeline_succeeds, @u_watcher, resource: project, value: false)
update_custom_notification(:merge_when_pipeline_succeeds, @subscriber, resource: project, value: false)
notification.merge_when_pipeline_succeeds(merge_request, assignee)
should_email(merge_request.author)
should_email(@u_watcher)
should_email(@subscriber)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment