Some refactoring - used class instead of hash for the query configuration
This commit is contained in:
parent
ca9ae8bf63
commit
f9fd0ff1ca
3 changed files with 95 additions and 46 deletions
|
@ -3,48 +3,6 @@ module Gitlab
|
|||
class EventsFetcher
|
||||
include MetricsFetcher
|
||||
|
||||
EVENTS_CONFIG = {
|
||||
issue: {
|
||||
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]],
|
||||
projections: [issue_table[:title], issue_table[:iid], issue_table[:created_at], user_table[:name], user_table[:email]]
|
||||
},
|
||||
plan: {
|
||||
start_time_attrs: issue_metrics_table[:first_associated_with_milestone_at],
|
||||
end_time_attrs: [issue_metrics_table[:first_added_to_board_at],
|
||||
issue_metrics_table[:first_mentioned_in_commit_at]],
|
||||
projections: [mr_diff_table[:st_commits].as('commits'), issue_metrics_table[:first_mentioned_in_commit_at]]
|
||||
},
|
||||
code: {
|
||||
start_time_attrs: issue_metrics_table[:first_mentioned_in_commit_at],
|
||||
end_time_attrs: mr_table[:created_at],
|
||||
projections: [mr_table[:title], mr_table[:iid], mr_table[:created_at], user_table[:name], user_table[:email]],
|
||||
order: mr_table[:created_at]
|
||||
},
|
||||
test: {
|
||||
start_time_attrs: mr_metrics_table[:latest_build_started_at],
|
||||
end_time_attrs: mr_metrics_table[:latest_build_finished_at],
|
||||
projections: mr_metrics_table[:ci_commit_id],
|
||||
order: mr_table[:created_at]
|
||||
},
|
||||
review: {
|
||||
start_time_attrs: mr_table[:created_at],
|
||||
end_time_attrs: mr_metrics_table[:merged_at],
|
||||
projections: [mr_table[:title], mr_table[:iid], mr_table[:created_at], user_table[:name], user_table[:email]]
|
||||
},
|
||||
staging: {
|
||||
start_time_attrs: mr_metrics_table[:merged_at],
|
||||
end_time_attrs: mr_metrics_table[:first_deployed_to_production_at],
|
||||
projections: mr_metrics_table[:ci_commit_id]
|
||||
},
|
||||
production: {
|
||||
start_time_attrs: issue_table[:created_at],
|
||||
end_time_attrs: mr_metrics_table[:first_deployed_to_production_at],
|
||||
projections: [issue_table[:title], issue_table[:iid], issue_table[:created_at], user_table[:name], user_table[:email]]
|
||||
},
|
||||
}.freeze
|
||||
|
||||
def initialize(project:, from:)
|
||||
@query = EventsQuery.new(project: project, from: from)
|
||||
end
|
||||
|
@ -52,11 +10,13 @@ module Gitlab
|
|||
def fetch(stage:)
|
||||
custom_query = "#{stage}_custom_query".to_sym
|
||||
|
||||
@query.execute(stage, EVENTS_CONFIG[stage]) do |base_query|
|
||||
public_send(custom_query, base_query) if self.respond_to?(custom_query)
|
||||
@query.execute(stage) do |base_query|
|
||||
send(custom_query, base_query) if self.respond_to?(custom_query)
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def issue_custom_query(base_query)
|
||||
base_query.join(user_table).on(issue_table[:author_id].eq(user_table[:id]))
|
||||
end
|
||||
|
|
|
@ -8,9 +8,9 @@ module Gitlab
|
|||
@from = from
|
||||
end
|
||||
|
||||
def execute(stage, config, &block)
|
||||
def execute(stage, &block)
|
||||
@stage = stage
|
||||
@config = config
|
||||
@config = QueryConfig.get(stage)
|
||||
query = build_query(&block)
|
||||
|
||||
ActiveRecord::Base.connection.execute(query.to_sql).to_a
|
||||
|
|
89
lib/gitlab/cycle_analytics/query_config.rb
Normal file
89
lib/gitlab/cycle_analytics/query_config.rb
Normal file
|
@ -0,0 +1,89 @@
|
|||
module Gitlab
|
||||
module CycleAnalytics
|
||||
class QueryConfig
|
||||
include MetricsFetcher
|
||||
|
||||
def self.get(*args)
|
||||
new(*args).get
|
||||
end
|
||||
|
||||
def initialize(stage)
|
||||
@stage = stage
|
||||
end
|
||||
|
||||
def get
|
||||
send(@stage).freeze if self.respond_to?(@stage)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def issue
|
||||
{ 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]],
|
||||
projections: [issue_table[:title],
|
||||
issue_table[:iid],
|
||||
issue_table[:created_at],
|
||||
user_table[:name],
|
||||
user_table[:email]]
|
||||
}
|
||||
end
|
||||
|
||||
def plan
|
||||
{ start_time_attrs: issue_metrics_table[:first_associated_with_milestone_at],
|
||||
end_time_attrs: [issue_metrics_table[:first_added_to_board_at],
|
||||
issue_metrics_table[:first_mentioned_in_commit_at]],
|
||||
projections: [mr_diff_table[:st_commits].as('commits'),
|
||||
issue_metrics_table[:first_mentioned_in_commit_at]]
|
||||
}
|
||||
end
|
||||
|
||||
def code
|
||||
{ start_time_attrs: issue_metrics_table[:first_mentioned_in_commit_at],
|
||||
end_time_attrs: mr_table[:created_at],
|
||||
projections: [mr_table[:title], mr_table[:iid],
|
||||
mr_table[:created_at],
|
||||
user_table[:name],
|
||||
user_table[:email]],
|
||||
order: mr_table[:created_at]
|
||||
}
|
||||
end
|
||||
|
||||
def test
|
||||
{ start_time_attrs: mr_metrics_table[:latest_build_started_at],
|
||||
end_time_attrs: mr_metrics_table[:latest_build_finished_at],
|
||||
projections: mr_metrics_table[:ci_commit_id],
|
||||
order: mr_table[:created_at]
|
||||
}
|
||||
end
|
||||
|
||||
def review
|
||||
{ start_time_attrs: mr_table[:created_at],
|
||||
end_time_attrs: mr_metrics_table[:merged_at],
|
||||
projections: [mr_table[:title], mr_table[:iid],
|
||||
mr_table[:created_at],
|
||||
user_table[:name],
|
||||
user_table[:email]]
|
||||
}
|
||||
end
|
||||
|
||||
def staging
|
||||
{ start_time_attrs: mr_metrics_table[:merged_at],
|
||||
end_time_attrs: mr_metrics_table[:first_deployed_to_production_at],
|
||||
projections: mr_metrics_table[:ci_commit_id]
|
||||
}
|
||||
end
|
||||
|
||||
def production
|
||||
{ start_time_attrs: issue_table[:created_at],
|
||||
end_time_attrs: mr_metrics_table[:first_deployed_to_production_at],
|
||||
projections: [issue_table[:title],
|
||||
issue_table[:iid],
|
||||
issue_table[:created_at],
|
||||
user_table[:name],
|
||||
user_table[:email]]
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue