1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
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 |stats, (stage_method, stage_text, stage_description)|
value = cycle_analytics.send(stage_method).presence
stats << {
title: stage_text,
description: stage_description,
value: value ? distance_of_time_in_words(value) : nil
}
stats
end
stats = nil if stats.all? { |stat| stat[:value].nil? }
summary = [
{ title: "New Issues", value: cycle_analytics.summary.new_issues },
{ title: "Commits", value: cycle_analytics.summary.commits },
{ title: "Deploys", value: cycle_analytics.summary.deploys }
]
{
summary: summary,
stats: stats
}
end
end
|