summaryrefslogtreecommitdiff
path: root/lib/api/entities/event.rb
blob: 9c2d766b7f1cbc2939094ef29283da325565b283 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# frozen_string_literal: true

module API
  module Entities
    class Event < Grape::Entity
      expose :project_id, :action_name
      expose :target_id, :target_iid, :target_type, :author_id
      expose :target_title
      expose :created_at
      expose :note, using: Entities::Note, if: ->(event, options) { event.note? }
      expose :author, using: Entities::UserBasic, if: ->(event, options) { event.author }

      expose :push_event_payload,
        as: :push_data,
        using: Entities::PushEventPayload,
        if: -> (event, _) { event.push_action? }

      expose :author_username do |event, options|
        event.author&.username
      end
    end
  end
end