diff options
author | James Lopez <james@jameslopez.es> | 2016-12-01 13:21:24 +0300 |
---|---|---|
committer | James Lopez <james@jameslopez.es> | 2017-01-17 13:32:55 +0300 |
commit | b8056669849729cab5700466a7fae6dc6b2743b2 (patch) | |
tree | 788c5a8bf535b48d3e1b8593f6be8a45205e317e /app | |
parent | 8183e848648bc737e4a09f76f4f55ee1cf106b26 (diff) |
refactor cycle analytics - updated based on MR feedback
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/projects/cycle_analytics/events_controller.rb | 16 | ||||
-rw-r--r-- | app/controllers/projects/cycle_analytics_controller.rb | 4 | ||||
-rw-r--r-- | app/models/cycle_analytics.rb | 12 | ||||
-rw-r--r-- | app/serializers/analytics_stage_entity.rb | 4 |
4 files changed, 15 insertions, 21 deletions
diff --git a/app/controllers/projects/cycle_analytics/events_controller.rb b/app/controllers/projects/cycle_analytics/events_controller.rb index e571e1dfce2..d4969c66467 100644 --- a/app/controllers/projects/cycle_analytics/events_controller.rb +++ b/app/controllers/projects/cycle_analytics/events_controller.rb @@ -9,33 +9,33 @@ module Projects before_action :authorize_read_merge_request!, only: [:code, :review] def issue - render_events(cycle_analytics.events_for(:issue)) + render_events(cycle_analytics[:issue].events) end def plan - render_events(cycle_analytics.events_for(:plan)) + render_events(cycle_analytics[:plan].events) end def code - render_events(cycle_analytics.events_for(:code)) + render_events(cycle_analytics[:code].events) end def test options(events_params)[:branch] = events_params[:branch_name] - render_events(cycle_analytics.events_for(:test)) + render_events(cycle_analytics[:test].events) end def review - render_events(cycle_analytics.events_for(:review)) + render_events(cycle_analytics[:review].events) end def staging - render_events(cycle_analytics.events_for(:staging)) + render_events(cycle_analytics[:staging].events) end def production - render_events(cycle_analytics.events_for(:production)) + render_events(cycle_analytics[:production].events) end private @@ -54,7 +54,7 @@ module Projects def events_params return {} unless params[:events].present? - params[:events].slice(:start_date, :branch_name) + params[:events].permit(:start_date, :branch_name) end end end diff --git a/app/controllers/projects/cycle_analytics_controller.rb b/app/controllers/projects/cycle_analytics_controller.rb index cf53d0a1919..88ac3ad046b 100644 --- a/app/controllers/projects/cycle_analytics_controller.rb +++ b/app/controllers/projects/cycle_analytics_controller.rb @@ -6,7 +6,7 @@ class Projects::CycleAnalyticsController < Projects::ApplicationController before_action :authorize_read_cycle_analytics! def show - @cycle_analytics = ::CycleAnalytics.new(@project, options: options(cycle_analytics_params)) + @cycle_analytics = ::CycleAnalytics.new(@project, options(cycle_analytics_params)) @cycle_analytics_no_data = @cycle_analytics.no_stats? @@ -21,7 +21,7 @@ class Projects::CycleAnalyticsController < Projects::ApplicationController def cycle_analytics_params return {} unless params[:cycle_analytics].present? - params[:cycle_analytics].slice(:start_date) + params[:cycle_analytics].permit(:start_date) end def cycle_analytics_json diff --git a/app/models/cycle_analytics.rb b/app/models/cycle_analytics.rb index 5bcc6fa1954..c6862c9733d 100644 --- a/app/models/cycle_analytics.rb +++ b/app/models/cycle_analytics.rb @@ -1,7 +1,7 @@ class CycleAnalytics STAGES = %i[issue plan code test review staging production].freeze - def initialize(project, options:) + def initialize(project, options) @project = project @options = options end @@ -22,19 +22,15 @@ class CycleAnalytics Gitlab::CycleAnalytics::Permissions.get(user: user, project: @project) end - def events_for(stage) - classify_stage(stage).new(project: @project, options: @options, stage: stage).events + def [](stage_name) + Gitlab::CycleAnalytics::Stage[stage_name].new(project: @project, options: @options) end private def stats_per_stage STAGES.map do |stage_name| - classify_stage(stage_name).new(project: @project, options: @options, stage: stage_name).median_data + Gitlab::CycleAnalytics::Stage[stage_name].new(project: @project, options: @options).median_data end end - - def classify_stage(stage_name) - "Gitlab::CycleAnalytics::#{stage_name.to_s.capitalize}Stage".constantize - end end diff --git a/app/serializers/analytics_stage_entity.rb b/app/serializers/analytics_stage_entity.rb index d454a4937f4..a559d0850c4 100644 --- a/app/serializers/analytics_stage_entity.rb +++ b/app/serializers/analytics_stage_entity.rb @@ -1,9 +1,7 @@ class AnalyticsStageEntity < Grape::Entity include EntityDateHelper - expose :stage, as: :title do |object| - object.stage.to_s.capitalize - end + expose :title expose :description expose :median, as: :value do |stage| |