2020-05-14 15:08:14 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class ServiceEventEntity < Grape::Entity
|
|
|
|
include RequestAwareEntity
|
|
|
|
|
|
|
|
expose :title do |event|
|
2022-02-28 00:18:02 +00:00
|
|
|
IntegrationsHelper.integration_event_title(event)
|
2020-05-14 15:08:14 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
expose :event_field_name, as: :name
|
|
|
|
|
|
|
|
expose :value do |event|
|
2021-06-24 15:07:28 +00:00
|
|
|
integration[event_field_name]
|
2020-05-14 15:08:14 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
expose :description do |event|
|
2021-07-06 21:07:50 +00:00
|
|
|
IntegrationsHelper.integration_event_description(integration, event)
|
2020-05-14 15:08:14 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
expose :field, if: -> (_, _) { event_field } do
|
|
|
|
expose :name do |event|
|
|
|
|
event_field[:name]
|
|
|
|
end
|
|
|
|
expose :value do |event|
|
2021-06-24 15:07:28 +00:00
|
|
|
integration.public_send(event_field[:name]) # rubocop:disable GitlabSecurity/PublicSend
|
2020-05-14 15:08:14 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
alias_method :event, :object
|
|
|
|
|
|
|
|
def event_field_name
|
2021-06-24 15:07:28 +00:00
|
|
|
IntegrationsHelper.integration_event_field_name(event)
|
2020-05-14 15:08:14 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def event_field
|
2021-06-24 15:07:28 +00:00
|
|
|
@event_field ||= integration.event_field(event)
|
2020-05-14 15:08:14 +00:00
|
|
|
end
|
|
|
|
|
2021-06-24 15:07:28 +00:00
|
|
|
def integration
|
2020-05-14 15:08:14 +00:00
|
|
|
request.service
|
|
|
|
end
|
|
|
|
end
|