2016-11-17 07:22:27 -05:00
|
|
|
module Gitlab
|
|
|
|
module CycleAnalytics
|
2016-12-02 11:09:29 -05:00
|
|
|
class BaseEventFetcher
|
2016-11-17 12:00:37 -05:00
|
|
|
include MetricsTables
|
2016-11-17 07:22:27 -05:00
|
|
|
|
2016-12-02 11:09:29 -05:00
|
|
|
attr_reader :projections, :query, :stage
|
2016-11-17 07:22:27 -05:00
|
|
|
|
2016-12-02 11:09:29 -05:00
|
|
|
def initialize(fetcher:, options:, stage:)
|
2016-12-01 06:44:35 -05:00
|
|
|
@fetcher = fetcher
|
2016-11-18 10:38:02 -05:00
|
|
|
@project = fetcher.project
|
2016-11-23 05:28:28 -05:00
|
|
|
@options = options
|
2016-12-02 11:09:29 -05:00
|
|
|
@stage = stage
|
2016-11-17 12:00:37 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def fetch
|
2016-11-17 14:54:02 -05:00
|
|
|
update_author!
|
2016-11-17 14:42:18 -05:00
|
|
|
|
|
|
|
event_result.map do |event|
|
2016-11-17 12:00:37 -05:00
|
|
|
serialize(event) if has_permission?(event['id'])
|
2016-11-23 03:10:04 -05:00
|
|
|
end.compact
|
2016-11-17 12:00:37 -05:00
|
|
|
end
|
2016-11-17 07:22:27 -05:00
|
|
|
|
2016-11-17 12:00:37 -05:00
|
|
|
def custom_query(_base_query); end
|
2016-11-17 07:22:27 -05:00
|
|
|
|
2016-11-17 12:00:37 -05:00
|
|
|
def order
|
|
|
|
@order || @start_time_attrs
|
|
|
|
end
|
2016-11-17 07:22:27 -05:00
|
|
|
|
2016-11-17 12:00:37 -05:00
|
|
|
private
|
2016-11-17 07:22:27 -05:00
|
|
|
|
2016-11-17 14:42:18 -05:00
|
|
|
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)
|
2016-11-17 14:42:18 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def event_result
|
2016-12-01 06:44:35 -05:00
|
|
|
@event_result ||= @fetcher.events(self).to_a
|
2016-11-17 14:42:18 -05:00
|
|
|
end
|
|
|
|
|
2016-11-17 12:00:37 -05:00
|
|
|
def serialize(_event)
|
|
|
|
raise NotImplementedError.new("Expected #{self.name} to implement serialize(event)")
|
|
|
|
end
|
|
|
|
|
2016-11-17 14:42:18 -05:00
|
|
|
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'] }
|
2016-11-17 07:22:27 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|