summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZ.J. van de Weg <git@zjvandeweg.nl>2017-03-23 08:16:48 +0100
committerZ.J. van de Weg <git@zjvandeweg.nl>2017-03-23 13:35:20 +0100
commit091c2608129445c6fe2dbe9a59e5fd3c78103d94 (patch)
tree047e20308c620e1c2d0a1955f490d3394aeec502
parentfed319b4ab763790865835eca35d179294883dd2 (diff)
downloadgitlab-ce-091c2608129445c6fe2dbe9a59e5fd3c78103d94.tar.gz
Improve readability and add test
-rw-r--r--app/models/project_services/chat_notification_service.rb17
-rw-r--r--spec/features/admin/admin_settings_spec.rb1
-rw-r--r--spec/support/slack_mattermost_notifications_shared_examples.rb19
3 files changed, 27 insertions, 10 deletions
diff --git a/app/models/project_services/chat_notification_service.rb b/app/models/project_services/chat_notification_service.rb
index 1a26d97283e..75834103db5 100644
--- a/app/models/project_services/chat_notification_service.rb
+++ b/app/models/project_services/chat_notification_service.rb
@@ -17,7 +17,7 @@ class ChatNotificationService < Service
if properties.nil?
self.properties = {}
self.notify_only_broken_pipelines = true
- self.notify_only_default_branch = false
+ self.notify_only_default_branch = true
end
end
@@ -137,20 +137,17 @@ class ChatNotificationService < Service
end
def should_pipeline_be_notified?(data)
- notify_for_branch(data) && notify_for_pipeline(data)
+ notify_for_ref?(data) && notify_for_pipeline?(data)
end
- def notify_for_branch(data)
- ref_type = data[:object_attributes][:tag] ? 'tag' : 'branch'
+ def notify_for_ref?(data)
+ return true if data[:object_attributes][:tag]
+ return true unless notify_only_default_branch
- if ref_type == 'branch' && notify_only_default_branch
- data[:object_attributes][:ref] == project.default_branch
- else
- true
- end
+ data[:object_attributes][:ref] == project.default_branch
end
- def notify_for_pipeline(data)
+ def notify_for_pipeline?(data)
case data[:object_attributes][:status]
when 'success'
!notify_only_broken_pipelines?
diff --git a/spec/features/admin/admin_settings_spec.rb b/spec/features/admin/admin_settings_spec.rb
index 03daab12c8f..5099441dce2 100644
--- a/spec/features/admin/admin_settings_spec.rb
+++ b/spec/features/admin/admin_settings_spec.rb
@@ -34,6 +34,7 @@ feature 'Admin updates settings', feature: true do
fill_in 'Username', with: 'test_user'
fill_in 'service_push_channel', with: '#test_channel'
page.check('Notify only broken pipelines')
+ page.check('Notify only default branch')
check_all_events
click_on 'Save'
diff --git a/spec/support/slack_mattermost_notifications_shared_examples.rb b/spec/support/slack_mattermost_notifications_shared_examples.rb
index 704922b6cf4..b902fe90707 100644
--- a/spec/support/slack_mattermost_notifications_shared_examples.rb
+++ b/spec/support/slack_mattermost_notifications_shared_examples.rb
@@ -324,5 +324,24 @@ RSpec.shared_examples 'slack or mattermost notifications' do
it_behaves_like 'call Slack/Mattermost API'
end
end
+
+ context 'only notify for the default branch' do
+ context 'when enabled' do
+ let(:pipeline) do
+ create(:ci_pipeline, project: project, status: 'failed', ref: 'not-the-default-branch')
+ end
+
+ before do
+ chat_service.notify_only_default_branch = true
+ end
+
+ it 'does not call the Slack/Mattermost API for pipeline events' do
+ data = Gitlab::DataBuilder::Pipeline.build(pipeline)
+ result = chat_service.execute(data)
+
+ expect(result).to be_falsy
+ end
+ end
+ end
end
end