diff options
author | Mayra Cabrera <mcabrera@gitlab.com> | 2019-05-28 20:38:35 +0000 |
---|---|---|
committer | Mayra Cabrera <mcabrera@gitlab.com> | 2019-05-28 20:38:35 +0000 |
commit | 85552d7ed75ad3ebd451748e264e89a479dd5aea (patch) | |
tree | 39b86412511b7dd569ba6ff1f4c0aef411670746 /app | |
parent | b54c5c8b410770d2b0062158b2fe069eb3cc86e9 (diff) | |
parent | 8f53e9ccc8771f1c8542a0b013a6e99ad6158ecd (diff) | |
download | gitlab-ce-85552d7ed75ad3ebd451748e264e89a479dd5aea.tar.gz |
Merge branch 'pipelines-email-default-branch-filter' into 'master'
Add notify_only_default_branch option to PipelinesEmailService
Closes #61721
See merge request gitlab-org/gitlab-ce!28271
Diffstat (limited to 'app')
-rw-r--r-- | app/models/project_services/pipelines_email_service.rb | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/app/models/project_services/pipelines_email_service.rb b/app/models/project_services/pipelines_email_service.rb index 7ba69370f14..ae5d5038099 100644 --- a/app/models/project_services/pipelines_email_service.rb +++ b/app/models/project_services/pipelines_email_service.rb @@ -2,11 +2,11 @@ class PipelinesEmailService < Service prop_accessor :recipients - boolean_accessor :notify_only_broken_pipelines + boolean_accessor :notify_only_broken_pipelines, :notify_only_default_branch validates :recipients, presence: true, if: :valid_recipients? def initialize_properties - self.properties ||= { notify_only_broken_pipelines: true } + self.properties ||= { notify_only_broken_pipelines: true, notify_only_default_branch: false } end def title @@ -54,7 +54,9 @@ class PipelinesEmailService < Service placeholder: _('Emails separated by comma'), required: true }, { type: 'checkbox', - name: 'notify_only_broken_pipelines' } + name: 'notify_only_broken_pipelines' }, + { type: 'checkbox', + name: 'notify_only_default_branch' } ] end @@ -67,6 +69,16 @@ class PipelinesEmailService < Service end def should_pipeline_be_notified?(data) + notify_for_pipeline_branch?(data) && notify_for_pipeline?(data) + end + + def notify_for_pipeline_branch?(data) + return true unless notify_only_default_branch? + + data[:object_attributes][:ref] == data[:project][:default_branch] + end + + def notify_for_pipeline?(data) case data[:object_attributes][:status] when 'success' !notify_only_broken_pipelines? |