提交 edb38d69 编写于 作者: T Timothy Andrew

Move cycle analytics JSON generation to a helper.

1. Use a new format, with each stage having a `title`, `description`,
   and `value.
上级 7d69ff3d
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
......
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
......@@ -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],
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册