Commit 671dba00 authored by alinamihaila's avatar alinamihaila

Add events counter cop

parent 63f1c564
......@@ -406,13 +406,8 @@ module Gitlab
# rubocop: disable CodeReuse/ActiveRecord
def merge_requests_users(time_period)
query =
Event
.where(target_type: Event::TARGET_TYPES[:merge_request].to_s)
.where(time_period)
distinct_count(
query,
Event.where(target_type: Event::TARGET_TYPES[:merge_request].to_s).where(time_period),
:author_id,
start: user_minimum_id,
finish: user_maximum_id
......
# frozen_string_literal: true
module RuboCop
module Cop
module Gitlab
class EventCounters < RuboCop::Cop::Cop
MSG = 'Use the `count` or `distinct_count`'
def_node_matcher :events_table, <<~PATTERN
$(send (const {nil cbase} :Event ) ...)
PATTERN
def on_send(node)
return unless usage_data_files?(node)
matched_node = events_table(node)
return if matched_node.nil?
method_name = matched_node.parent.children[1]
add_offense(node, location: :expression) unless [:count, :distinct_count].include?(method_name)
end
private
def usage_data_files?(node)
path = node.location.expression.source_buffer.name
path.include?('usage_data.rb')
end
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment