gitlab-org--gitlab-foss/lib/gitlab/cycle_analytics/base_event_fetcher.rb

59 lines
1.2 KiB
Ruby
Raw Normal View History

module Gitlab
module CycleAnalytics
2016-12-02 11:09:29 -05:00
class BaseEventFetcher
include MetricsTables
2016-12-02 11:09:29 -05:00
attr_reader :projections, :query, :stage
2016-12-02 11:09:29 -05:00
def initialize(fetcher:, options:, stage:)
2016-12-01 06:44:35 -05:00
@fetcher = fetcher
@project = fetcher.project
2016-11-23 05:28:28 -05:00
@options = options
2016-12-02 11:09:29 -05:00
@stage = stage
end
def fetch
2016-11-17 14:54:02 -05:00
update_author!
event_result.map do |event|
serialize(event) if has_permission?(event['id'])
end.compact
end
def custom_query(_base_query); end
def order
@order || @start_time_attrs
end
private
def update_author!
2016-11-17 14:54:02 -05:00
return unless event_result.any? && event_result.first['author_id']
2016-11-18 07:00:38 -05:00
Updater.update!(event_result, from: 'author_id', to: 'author', klass: User)
end
def event_result
2016-12-01 06:44:35 -05:00
@event_result ||= @fetcher.events(self).to_a
end
def serialize(_event)
raise NotImplementedError.new("Expected #{self.name} to implement serialize(event)")
end
def has_permission?(id)
allowed_ids.nil? || allowed_ids.include?(id.to_i)
end
def allowed_ids
nil
end
def event_result_ids
event_result.map { |event| event['id'] }
end
end
end
end