diff options
author | Stan Hu <stanhu@gmail.com> | 2019-09-02 13:25:16 +0000 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2019-09-02 13:25:16 +0000 |
commit | bdd67a659e92b9da95c48e891183854c66d93fb8 (patch) | |
tree | daf1127dd1bfb156aeb26345a4b7cb5da21e2e96 | |
parent | 60fd42172fcf790b3cb612a3403227d4a97035a6 (diff) | |
parent | 9260706d7b3488593df8c842eb103cc589c7ec72 (diff) | |
download | gitlab-ce-bdd67a659e92b9da95c48e891183854c66d93fb8.tar.gz |
Merge branch 'pl-fix-chat-notification-service' into 'master'
CE: Reduce amount of property definitions in ChatNotificationService
See merge request gitlab-org/gitlab-ce!32363
-rw-r--r-- | app/models/project_services/chat_notification_service.rb | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/app/models/project_services/chat_notification_service.rb b/app/models/project_services/chat_notification_service.rb index 7c9ecc6b821..cb75c89136e 100644 --- a/app/models/project_services/chat_notification_service.rb +++ b/app/models/project_services/chat_notification_service.rb @@ -5,17 +5,25 @@ class ChatNotificationService < Service include ChatMessage + SUPPORTED_EVENTS = %w[ + push issue confidential_issue merge_request note confidential_note + tag_push pipeline wiki_page deployment + ].freeze + + EVENT_CHANNEL = proc { |event| "#{event}_channel" } + default_value_for :category, 'chat' prop_accessor :webhook, :username, :channel + + # Custom serialized properties initialization + prop_accessor(*SUPPORTED_EVENTS.map { |event| EVENT_CHANNEL[event] }) + boolean_accessor :notify_only_broken_pipelines, :notify_only_default_branch validates :webhook, presence: true, public_url: true, if: :activated? def initialize_properties - # Custom serialized properties initialization - self.supported_events.each { |event| self.class.prop_accessor(event_channel_name(event)) } - if properties.nil? self.properties = {} self.notify_only_broken_pipelines = true @@ -32,8 +40,7 @@ class ChatNotificationService < Service end def self.supported_events - %w[push issue confidential_issue merge_request note confidential_note tag_push - pipeline wiki_page deployment] + SUPPORTED_EVENTS end def fields @@ -139,7 +146,7 @@ class ChatNotificationService < Service end def event_channel_name(event) - "#{event}_channel" + EVENT_CHANNEL[event] end def project_name |