summaryrefslogtreecommitdiff
path: root/app/controllers/projects/cycle_analytics_controller.rb
diff options
context:
space:
mode:
authorPhil Hughes <me@iamphill.com>2016-10-03 09:10:20 +0100
committerPhil Hughes <me@iamphill.com>2016-10-03 09:10:20 +0100
commitcc88fa4d5be9ec0d5fb42f1bb5efa0b82f30a589 (patch)
tree1b9facaf15466aa7f5b0393e97cb1eabfdcafa7e /app/controllers/projects/cycle_analytics_controller.rb
parent69db604e55de2bdf1a28c274be6cc9131534517d (diff)
parentf2c0f8237124d2dc539120bd77f301f216453cb7 (diff)
downloadgitlab-ce-cc88fa4d5be9ec0d5fb42f1bb5efa0b82f30a589.tar.gz
Merge branch 'master' into revert-c676283b
Diffstat (limited to 'app/controllers/projects/cycle_analytics_controller.rb')
-rw-r--r--app/controllers/projects/cycle_analytics_controller.rb67
1 files changed, 67 insertions, 0 deletions
diff --git a/app/controllers/projects/cycle_analytics_controller.rb b/app/controllers/projects/cycle_analytics_controller.rb
new file mode 100644
index 00000000000..16a7b1fc6e2
--- /dev/null
+++ b/app/controllers/projects/cycle_analytics_controller.rb
@@ -0,0 +1,67 @@
+class Projects::CycleAnalyticsController < Projects::ApplicationController
+ include ActionView::Helpers::DateHelper
+ include ActionView::Helpers::TextHelper
+
+ before_action :authorize_read_cycle_analytics!
+
+ def show
+ @cycle_analytics = CycleAnalytics.new(@project, from: parse_start_date)
+
+ respond_to do |format|
+ format.html
+ format.json { render json: cycle_analytics_json }
+ end
+ end
+
+ private
+
+ def parse_start_date
+ case cycle_analytics_params[:start_date]
+ when '30' then 30.days.ago
+ when '90' then 90.days.ago
+ else 90.days.ago
+ end
+ end
+
+ def cycle_analytics_params
+ return {} unless params[:cycle_analytics].present?
+
+ { start_date: params[:cycle_analytics][:start_date] }
+ end
+
+ def cycle_analytics_json
+ 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 merge request creation and merge/close"],
+ [:staging, "Staging", "From merge request merge until deploy to production"],
+ [:production, "Production", "From issue creation until deploy to production"]]
+
+ stats = cycle_analytics_view_data.reduce([]) do |stats, (stage_method, stage_text, stage_description)|
+ value = @cycle_analytics.send(stage_method).presence
+
+ stats << {
+ title: stage_text,
+ description: stage_description,
+ value: value && !value.zero? ? distance_of_time_in_words(value) : nil
+ }
+ stats
+ end
+
+ issues = @cycle_analytics.summary.new_issues
+ commits = @cycle_analytics.summary.commits
+ deploys = @cycle_analytics.summary.deploys
+
+ summary = [
+ { title: "New Issue".pluralize(issues), value: issues },
+ { title: "Commit".pluralize(commits), value: commits },
+ { title: "Deploy".pluralize(deploys), value: deploys }
+ ]
+
+ {
+ summary: summary,
+ stats: stats
+ }
+ end
+end