diff options
author | Timothy Andrew <mail@timothyandrew.net> | 2016-09-17 12:08:23 +0530 |
---|---|---|
committer | Timothy Andrew <mail@timothyandrew.net> | 2016-09-17 12:16:48 +0530 |
commit | edb38d69cc6cffef46b6c7b957ad97ce213173cf (patch) | |
tree | e41eae3d77847cd4189ef3c7c21d29543c8fa0ea | |
parent | 7d69ff3ddf0fb83c6a1ec02f85b01b454080b647 (diff) | |
download | gitlab-ce-edb38d69cc6cffef46b6c7b957ad97ce213173cf.tar.gz |
Move cycle analytics JSON generation to a helper.
1. Use a new format, with each stage having a `title`, `description`,
and `value.
-rw-r--r-- | app/controllers/projects/cycle_analytics_controller.rb | 4 | ||||
-rw-r--r-- | app/helpers/cycle_analytics_helper.rb | 24 | ||||
-rw-r--r-- | app/models/cycle_analytics.rb | 7 |
3 files changed, 27 insertions, 8 deletions
diff --git a/app/controllers/projects/cycle_analytics_controller.rb b/app/controllers/projects/cycle_analytics_controller.rb index 9903fae6f7d..dd0acc57425 100644 --- a/app/controllers/projects/cycle_analytics_controller.rb +++ b/app/controllers/projects/cycle_analytics_controller.rb @@ -1,4 +1,6 @@ class Projects::CycleAnalyticsController < Projects::ApplicationController + include CycleAnalyticsHelper + before_action :authorize_read_cycle_analytics! def show @@ -6,7 +8,7 @@ class Projects::CycleAnalyticsController < Projects::ApplicationController respond_to do |format| format.html - format.json { render json: @cycle_analytics } + format.json { render json: cycle_analytics_json(@cycle_analytics) } end end diff --git a/app/helpers/cycle_analytics_helper.rb b/app/helpers/cycle_analytics_helper.rb new file mode 100644 index 00000000000..c49c51642ed --- /dev/null +++ b/app/helpers/cycle_analytics_helper.rb @@ -0,0 +1,24 @@ +module CycleAnalyticsHelper + include ActionView::Helpers::DateHelper + + def cycle_analytics_json(cycle_analytics) + cycle_analytics_view_data = [[:issue, "Issue", "Time before an issue gets scheduled"], + [:plan, "Plan", "Time before an issue starts implementation"], + [:code, "Code", "Time until first merge request"], + [:test, "Test", "Total test time for all commits/merges"], + [:review, "Review", "Time between MR creation and merge/close"], + [:staging, "Staging", "From MR merge until deploy to production"], + [:production, "Production", "From issue creation until deploy to production"]] + + stats = cycle_analytics_view_data.reduce({}) do |hash, (stage_method, stage_text, stage_description)| + hash[stage_method] = { + title: stage_text, + description: stage_description, + value: distance_of_time_in_words(cycle_analytics.send(stage_method)) + } + hash + end + + { stats: stats } + end +end diff --git a/app/models/cycle_analytics.rb b/app/models/cycle_analytics.rb index c26d50d693c..5f09e5d611b 100644 --- a/app/models/cycle_analytics.rb +++ b/app/models/cycle_analytics.rb @@ -6,13 +6,6 @@ class CycleAnalytics @from = from end - def as_json(options = {}) - { - issue: issue, plan: plan, code: code, test: test, - review: review, staging: staging, production: production - } - end - def issue calculate_metric!(:issue, TableReferences.issues[:created_at], |