2021-05-10 18:10:41 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Gitlab
|
|
|
|
module Integrations
|
|
|
|
class StiType < ActiveRecord::Type::String
|
|
|
|
NAMESPACED_INTEGRATIONS = Set.new(%w(
|
2021-05-25 18:10:42 +00:00
|
|
|
Asana Assembla Bamboo Bugzilla Buildkite Campfire Confluence CustomIssueTracker Datadog
|
2021-06-18 15:10:16 +00:00
|
|
|
Discord DroneCi EmailsOnPush Ewm ExternalWiki Flowdock HangoutsChat Irker Jenkins Jira Mattermost
|
|
|
|
MattermostSlashCommands MicrosoftTeams MockCi MockMonitoring Packagist PipelinesEmail Pivotaltracker
|
2021-08-04 18:09:57 +00:00
|
|
|
Prometheus Pushover Redmine Slack SlackSlashCommands Teamcity UnifyCircuit WebexTeams Youtrack
|
2021-05-10 18:10:41 +00:00
|
|
|
)).freeze
|
|
|
|
|
2021-07-29 06:10:15 +00:00
|
|
|
def self.namespaced_integrations
|
|
|
|
NAMESPACED_INTEGRATIONS
|
|
|
|
end
|
|
|
|
|
2021-05-10 18:10:41 +00:00
|
|
|
def cast(value)
|
|
|
|
new_cast(value) || super
|
|
|
|
end
|
|
|
|
|
|
|
|
def serialize(value)
|
|
|
|
new_serialize(value) || super
|
|
|
|
end
|
|
|
|
|
|
|
|
def deserialize(value)
|
|
|
|
value
|
|
|
|
end
|
|
|
|
|
|
|
|
def changed?(original_value, value, _new_value_before_type_cast)
|
|
|
|
original_value != serialize(value)
|
|
|
|
end
|
|
|
|
|
|
|
|
def changed_in_place?(original_value_for_database, value)
|
|
|
|
original_value_for_database != serialize(value)
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def new_cast(value)
|
|
|
|
value = prepare_value(value)
|
|
|
|
return unless value
|
|
|
|
|
|
|
|
stripped_name = value.delete_suffix('Service')
|
2021-07-29 06:10:15 +00:00
|
|
|
return unless self.class.namespaced_integrations.include?(stripped_name)
|
2021-05-10 18:10:41 +00:00
|
|
|
|
|
|
|
"Integrations::#{stripped_name}"
|
|
|
|
end
|
|
|
|
|
|
|
|
def new_serialize(value)
|
|
|
|
value = prepare_value(value)
|
|
|
|
return unless value&.starts_with?('Integrations::')
|
|
|
|
|
|
|
|
"#{value.delete_prefix('Integrations::')}Service"
|
|
|
|
end
|
|
|
|
|
|
|
|
# Returns value cast to a `String`, or `nil` if value is `nil`.
|
|
|
|
def prepare_value(value)
|
|
|
|
return value if value.nil? || value.is_a?(String)
|
|
|
|
|
|
|
|
value.to_s
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2021-06-02 15:09:59 +00:00
|
|
|
|
|
|
|
Gitlab::Integrations::StiType.prepend_mod
|