debian-mirror-gitlab/app/serializers/service_event_entity.rb

45 lines
916 B
Ruby
Raw Normal View History

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