Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'app/models/project_services/chat_notification_service.rb')
-rw-r--r--app/models/project_services/chat_notification_service.rb25
1 files changed, 14 insertions, 11 deletions
diff --git a/app/models/project_services/chat_notification_service.rb b/app/models/project_services/chat_notification_service.rb
index cb75c89136e..ecea1a5b630 100644
--- a/app/models/project_services/chat_notification_service.rb
+++ b/app/models/project_services/chat_notification_service.rb
@@ -4,6 +4,7 @@
# This class is not meant to be used directly, but only to inherit from.
class ChatNotificationService < Service
include ChatMessage
+ include NotificationBranchSelection
SUPPORTED_EVENTS = %w[
push issue confidential_issue merge_request note confidential_note
@@ -14,7 +15,7 @@ class ChatNotificationService < Service
default_value_for :category, 'chat'
- prop_accessor :webhook, :username, :channel
+ prop_accessor :webhook, :username, :channel, :branches_to_be_notified
# Custom serialized properties initialization
prop_accessor(*SUPPORTED_EVENTS.map { |event| EVENT_CHANNEL[event] })
@@ -27,7 +28,16 @@ class ChatNotificationService < Service
if properties.nil?
self.properties = {}
self.notify_only_broken_pipelines = true
- self.notify_only_default_branch = true
+ self.branches_to_be_notified = "default"
+ elsif !self.notify_only_default_branch.nil?
+ # In older versions, there was only a boolean property named
+ # `notify_only_default_branch`. Now we have a string property named
+ # `branches_to_be_notified`. Instead of doing a background migration, we
+ # opted to set a value for the new property based on the old one, if
+ # users hasn't specified one already. When users edit the service and
+ # selects a value for this new property, it will override everything.
+
+ self.branches_to_be_notified ||= notify_only_default_branch? ? "default" : "all"
end
end
@@ -52,7 +62,7 @@ class ChatNotificationService < Service
{ type: 'text', name: 'webhook', placeholder: "e.g. #{webhook_placeholder}", required: true },
{ type: 'text', name: 'username', placeholder: 'e.g. GitLab' },
{ type: 'checkbox', name: 'notify_only_broken_pipelines' },
- { type: 'checkbox', name: 'notify_only_default_branch' }
+ { type: 'select', name: 'branches_to_be_notified', choices: BRANCH_CHOICES }
]
end
@@ -168,15 +178,8 @@ class ChatNotificationService < Service
def notify_for_ref?(data)
return true if data[:object_kind] == 'tag_push'
return true if data.dig(:object_attributes, :tag)
- return true unless notify_only_default_branch?
- ref = if data[:ref]
- Gitlab::Git.ref_name(data[:ref])
- else
- data.dig(:object_attributes, :ref)
- end
-
- ref == project.default_branch
+ notify_for_branch?(data)
end
def notify_for_pipeline?(data)