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