Commit bdd67a65 authored by Stan Hu's avatar Stan Hu

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
parents 60fd4217 9260706d
...@@ -5,17 +5,25 @@ ...@@ -5,17 +5,25 @@
class ChatNotificationService < Service class ChatNotificationService < Service
include ChatMessage 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' default_value_for :category, 'chat'
prop_accessor :webhook, :username, :channel 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 boolean_accessor :notify_only_broken_pipelines, :notify_only_default_branch
validates :webhook, presence: true, public_url: true, if: :activated? validates :webhook, presence: true, public_url: true, if: :activated?
def initialize_properties def initialize_properties
# Custom serialized properties initialization
self.supported_events.each { |event| self.class.prop_accessor(event_channel_name(event)) }
if properties.nil? if properties.nil?
self.properties = {} self.properties = {}
self.notify_only_broken_pipelines = true self.notify_only_broken_pipelines = true
...@@ -32,8 +40,7 @@ class ChatNotificationService < Service ...@@ -32,8 +40,7 @@ class ChatNotificationService < Service
end end
def self.supported_events def self.supported_events
%w[push issue confidential_issue merge_request note confidential_note tag_push SUPPORTED_EVENTS
pipeline wiki_page deployment]
end end
def fields def fields
...@@ -139,7 +146,7 @@ class ChatNotificationService < Service ...@@ -139,7 +146,7 @@ class ChatNotificationService < Service
end end
def event_channel_name(event) def event_channel_name(event)
"#{event}_channel" EVENT_CHANNEL[event]
end end
def project_name def project_name
......
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