refactored a bunch of stuff based on feedback

This commit is contained in:
James Lopez 2017-01-12 12:48:01 +01:00
parent 34875ce6b7
commit 150a448596
12 changed files with 54 additions and 48 deletions

View file

@ -17,7 +17,7 @@ class CycleAnalytics
end
def no_stats?
stats.map { |hash| hash[:value] }.compact.empty?
stats.all? { hash[:value].nil? }
end
def permissions(user:)
@ -32,7 +32,7 @@ class CycleAnalytics
def stats_per_stage
STAGES.map do |stage_name|
self[stage_name].median_data
self[stage_name].as_json
end
end
end

View file

@ -42,7 +42,7 @@ module Gitlab
end
def default_order
@options[:start_time_attrs].is_a?(Array) ? @options[:start_time_attrs].first : @options[:start_time_attrs]
[@options[:start_time_attrs]].flatten.first
end
def serialize(_event)

View file

@ -8,17 +8,11 @@ module Gitlab
@options = options
end
def event
@event ||= Gitlab::CycleAnalytics::Event[name].new(project: @project,
stage: name,
options: event_options)
end
def events
event.fetch
event_fetcher.fetch
end
def median_data
def as_json
AnalyticsStageSerializer.new.represent(self).as_json
end
@ -35,7 +29,7 @@ module Gitlab
# cycle analytics stage.
interval_query = Arel::Nodes::As.new(
cte_table,
subtract_datetimes(base_query.dup, @start_time_attrs, @end_time_attrs, name.to_s))
subtract_datetimes(base_query.dup, start_time_attrs, end_time_attrs, name.to_s))
median_datetime(cte_table, interval_query, name)
end
@ -46,8 +40,14 @@ module Gitlab
private
def event_fetcher
@event_fetcher ||= Gitlab::CycleAnalytics::EventFetcher[name].new(project: @project,
stage: name,
options: event_options)
end
def event_options
@options.merge(start_time_attrs: @start_time_attrs, end_time_attrs: @end_time_attrs)
@options.merge(start_time_attrs: start_time_attrs, end_time_attrs: end_time_attrs)
end
end
end

View file

@ -1,11 +1,12 @@
module Gitlab
module CycleAnalytics
class CodeStage < BaseStage
def initialize(*args)
@start_time_attrs = issue_metrics_table[:first_mentioned_in_commit_at]
@end_time_attrs = mr_table[:created_at]
def start_time_attrs
@start_time_attrs ||= issue_metrics_table[:first_mentioned_in_commit_at]
end
super(*args)
def end_time_attrs
@end_time_attrs ||= mr_table[:created_at]
end
def name

View file

@ -1,6 +1,6 @@
module Gitlab
module CycleAnalytics
module Event
module EventFetcher
def self.[](stage_name)
CycleAnalytics.const_get("#{stage_name.to_s.camelize}EventFetcher")
end

View file

@ -1,12 +1,13 @@
module Gitlab
module CycleAnalytics
class IssueStage < BaseStage
def initialize(*args)
@start_time_attrs = issue_table[:created_at]
@end_time_attrs = [issue_metrics_table[:first_associated_with_milestone_at],
issue_metrics_table[:first_added_to_board_at]]
def start_time_attrs
@start_time_attrs ||= issue_table[:created_at]
end
super(*args)
def end_time_attrs
@end_time_attrs ||= [issue_metrics_table[:first_associated_with_milestone_at],
issue_metrics_table[:first_added_to_board_at]]
end
def name

View file

@ -1,12 +1,13 @@
module Gitlab
module CycleAnalytics
class PlanStage < BaseStage
def initialize(*args)
@start_time_attrs = [issue_metrics_table[:first_associated_with_milestone_at],
def start_time_attrs
@start_time_attrs ||= [issue_metrics_table[:first_associated_with_milestone_at],
issue_metrics_table[:first_added_to_board_at]]
@end_time_attrs = issue_metrics_table[:first_mentioned_in_commit_at]
end
super(*args)
def end_time_attrs
@end_time_attrs ||= issue_metrics_table[:first_mentioned_in_commit_at]
end
def name

View file

@ -3,11 +3,12 @@ module Gitlab
class ProductionStage < BaseStage
include ProductionHelper
def initialize(*args)
@start_time_attrs = issue_table[:created_at]
@end_time_attrs = mr_metrics_table[:first_deployed_to_production_at]
def start_time_attrs
@start_time_attrs ||= issue_table[:created_at]
end
super(*args)
def end_time_attrs
@end_time_attrs ||= mr_metrics_table[:first_deployed_to_production_at]
end
def name

View file

@ -1,11 +1,12 @@
module Gitlab
module CycleAnalytics
class ReviewStage < BaseStage
def initialize(*args)
@start_time_attrs = mr_table[:created_at]
@end_time_attrs = mr_metrics_table[:merged_at]
def start_time_attrs
@start_time_attrs ||= mr_table[:created_at]
end
super(*args)
def end_time_attrs
@end_time_attrs ||= mr_metrics_table[:merged_at]
end
def name

View file

@ -2,12 +2,12 @@ module Gitlab
module CycleAnalytics
class StagingStage < BaseStage
include ProductionHelper
def start_time_attrs
@start_time_attrs ||= mr_metrics_table[:merged_at]
end
def initialize(*args)
@start_time_attrs = mr_metrics_table[:merged_at]
@end_time_attrs = mr_metrics_table[:first_deployed_to_production_at]
super(*args)
def end_time_attrs
@end_time_attrs ||= mr_metrics_table[:first_deployed_to_production_at]
end
def name

View file

@ -1,11 +1,12 @@
module Gitlab
module CycleAnalytics
class TestStage < BaseStage
def initialize(*args)
@start_time_attrs = mr_metrics_table[:latest_build_started_at]
@end_time_attrs = mr_metrics_table[:latest_build_finished_at]
def start_time_attrs
@start_time_attrs ||= mr_metrics_table[:latest_build_started_at]
end
super(*args)
def end_time_attrs
@end_time_attrs ||= mr_metrics_table[:latest_build_finished_at]
end
def name

View file

@ -9,15 +9,15 @@ shared_examples 'base stage' do
end
it 'has the median data value' do
expect(stage.median_data[:value]).not_to be_nil
expect(stage.as_json[:value]).not_to be_nil
end
it 'has the median data stage' do
expect(stage.median_data[:title]).not_to be_nil
expect(stage.as_json[:title]).not_to be_nil
end
it 'has the median data description' do
expect(stage.median_data[:description]).not_to be_nil
expect(stage.as_json[:description]).not_to be_nil
end
it 'has the title' do