Class: Integrations::BaseChatNotification
Constant Summary
collapse
- SUPPORTED_EVENTS =
%w[
push issue confidential_issue merge_request note confidential_note
tag_push pipeline wiki_page deployment incident
].freeze
- SUPPORTED_EVENTS_FOR_LABEL_FILTER =
%w[issue confidential_issue merge_request note confidential_note].freeze
- EVENT_CHANNEL =
proc { |event| "#{event}_channel" }
- LABEL_NOTIFICATION_BEHAVIOURS =
[
MATCH_ANY_LABEL = 'match_any',
MATCH_ALL_LABELS = 'match_all'
].freeze
- SECRET_MASK =
'************'
Constants inherited
from Integration
Integration::BASE_CLASSES, Integration::DEV_INTEGRATION_NAMES, Integration::INTEGRATION_NAMES, Integration::PROJECT_SPECIFIC_INTEGRATION_NAMES, Integration::SECTION_TYPE_CONFIGURATION, Integration::SECTION_TYPE_CONNECTION, Integration::SECTION_TYPE_TRIGGER, Integration::SNOWPLOW_EVENT_ACTION, Integration::SNOWPLOW_EVENT_LABEL, Integration::UnknownType
ApplicationRecord::MAX_PLUCK
ResetOnUnionError::MAX_RESET_PERIOD
Instance Attribute Summary
Attributes included from Importable
#imported, #importing
Class Method Summary
collapse
Instance Method Summary
collapse
#notify_for_branch?
Methods inherited from Integration
#activate_disabled_reason, #activated?, #async_execute, #attributes, available_integration_names, available_integration_types, boolean_accessor, build_from_integration, #category, #chat?, #ci?, #configurable_events, create_from_active_default_integrations, default_integration, #default_test_event, default_test_event, #description, dev_integration_names, #dup, #editable?, event_description, event_names, #event_names, field, fields, find_or_initialize_all_non_project_specific, find_or_initialize_non_project_specific_integration, #group_level?, #inheritable?, inherited_descendants_from_self_or_ancestors_from, instance_exists_for?, #instance_level?, integration_name_to_model, integration_name_to_type, integration_names, #json_fields, #operating?, #parent, #project_level?, project_specific_integration_names, prop_accessor, #properties=, #reencrypt_properties, #reset_updated_properties, #secret_fields, #show_active_box?, #supported_events, #supports_data_fields?, #test, #testable?, #title, #to_database_hash, #to_param, to_param, #updated_properties
#extended, extensions, #included, #method_added, #override, #prepended, #queue_verification, verify!
#exposing_secrets_fields
Methods included from Loggable
#build_message, #log_error, #log_exception, #log_info, #logger
cached_column_list, #create_or_load_association, declarative_enum, default_select_columns, id_in, id_not_in, iid_in, pluck_primary_key, primary_key_in, #readable_by?, safe_ensure_unique, safe_find_or_create_by, safe_find_or_create_by!, #to_ability_name, underscore, where_exists, where_not_exists, with_fast_read_statement_timeout, without_order
#serializable_hash
Class Method Details
.requires_webhook? ⇒ Boolean
156
157
158
|
# File 'app/models/integrations/base_chat_notification.rb', line 156
def self.requires_webhook?
true
end
|
.supported_events ⇒ Object
70
71
72
|
# File 'app/models/integrations/base_chat_notification.rb', line 70
def self.supported_events
SUPPORTED_EVENTS
end
|
Instance Method Details
#api_field_names ⇒ Object
117
118
119
120
121
122
123
|
# File 'app/models/integrations/base_chat_notification.rb', line 117
def api_field_names
if mask_configurable_channels?
super - event_channel_names
else
super
end
end
|
#channel_limit_per_event ⇒ Object
160
161
162
|
# File 'app/models/integrations/base_chat_notification.rb', line 160
def channel_limit_per_event
10
end
|
#confidential_issue_channel ⇒ Object
62
63
64
|
# File 'app/models/integrations/base_chat_notification.rb', line 62
def confidential_issue_channel
properties['confidential_issue_channel'].presence || properties['issue_channel']
end
|
#confidential_note_channel ⇒ Object
66
67
68
|
# File 'app/models/integrations/base_chat_notification.rb', line 66
def confidential_note_channel
properties['confidential_note_channel'].presence || properties['note_channel']
end
|
#configurable_channels? ⇒ Boolean
With some integrations the webhook is already tied to a specific channel, for others the channels are configurable for each event.
143
144
145
|
# File 'app/models/integrations/base_chat_notification.rb', line 143
def configurable_channels?
false
end
|
#default_channel_placeholder ⇒ Object
129
130
131
|
# File 'app/models/integrations/base_chat_notification.rb', line 129
def default_channel_placeholder
raise NotImplementedError
end
|
#event_channel_name(event) ⇒ Object
147
148
149
|
# File 'app/models/integrations/base_chat_notification.rb', line 147
def event_channel_name(event)
EVENT_CHANNEL[event]
end
|
#event_channel_names ⇒ Object
110
111
112
113
114
|
# File 'app/models/integrations/base_chat_notification.rb', line 110
def event_channel_names
return [] unless configurable_channels?
supported_events.map { |event| event_channel_name(event) }
end
|
#event_channel_value(event) ⇒ Object
151
152
153
154
|
# File 'app/models/integrations/base_chat_notification.rb', line 151
def event_channel_value(event)
field_name = event_channel_name(event)
self.public_send(field_name) end
|
#execute(data) ⇒ Object
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
# File 'app/models/integrations/base_chat_notification.rb', line 78
def execute(data)
object_kind = data[:object_kind]
return false unless should_execute?(object_kind)
data = custom_data(data)
return false unless notify_label?(data)
message = get_message(object_kind, data)
return false unless message
event = data[:event_type] || object_kind
channels = channels_for_event(event)
opts = {}
opts[:channel] = channels if channels.present?
opts[:username] = username if username
if notify(message, opts)
log_usage(event, user_id_from_hook_data(data))
return true
end
false
end
|
#fields ⇒ Object
74
75
76
|
# File 'app/models/integrations/base_chat_notification.rb', line 74
def fields
self.class.fields + build_event_channels
end
|
125
126
127
|
# File 'app/models/integrations/base_chat_notification.rb', line 125
def form_fields
super.reject { |field| field[:name].end_with?('channel') }
end
|
#help ⇒ Object
137
138
139
|
# File 'app/models/integrations/base_chat_notification.rb', line 137
def help
raise NotImplementedError
end
|
#initialize_properties ⇒ Object
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
# File 'app/models/integrations/base_chat_notification.rb', line 43
def initialize_properties
super
if properties.empty?
self.notify_only_broken_pipelines = true if self.respond_to?(:notify_only_broken_pipelines)
self.branches_to_be_notified = "default"
self.labels_to_be_notified_behavior = MATCH_ANY_LABEL
elsif !self.notify_only_default_branch.nil?
self.branches_to_be_notified ||= notify_only_default_branch? ? "default" : "all"
end
end
|
#mask_configurable_channels? ⇒ Boolean
164
165
166
|
# File 'app/models/integrations/base_chat_notification.rb', line 164
def mask_configurable_channels?
false
end
|
#sections ⇒ Object
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
|
# File 'app/models/integrations/base_chat_notification.rb', line 169
def sections
[
{
type: SECTION_TYPE_CONNECTION,
title: s_('Integrations|Connection details'),
description: help
},
{
type: SECTION_TYPE_TRIGGER,
title: s_('Integrations|Trigger'),
description: s_('Integrations|An event will be triggered when one of the following items happen.')
},
{
type: SECTION_TYPE_CONFIGURATION,
title: s_('Integrations|Notification settings'),
description: s_('Integrations|Configure the scope of notifications.')
}
]
end
|
#webhook_help ⇒ Object
133
134
135
|
# File 'app/models/integrations/base_chat_notification.rb', line 133
def webhook_help
raise NotImplementedError
end
|