diff options
author | Timothy Andrew <mail@timothyandrew.net> | 2016-09-19 12:30:55 +0300 |
---|---|---|
committer | Timothy Andrew <mail@timothyandrew.net> | 2016-09-19 12:30:55 +0300 |
commit | 4531e433ad33e67cb66abaa4626b5e608eb11f11 (patch) | |
tree | e2199500817186477599b226f32d5acb778a2cc0 /app/helpers | |
parent | 2cddd02ec5dd9d27fc9e9b6ac5e0748fe92e1cff (diff) |
Make changes to the cycle analytics JSON endpoint.
1. Add `summary` section.
2. `stats` is `null` if no stats are present.
3. `stats` and `summary` are both arrays.
Diffstat (limited to 'app/helpers')
-rw-r--r-- | app/helpers/cycle_analytics_helper.rb | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/app/helpers/cycle_analytics_helper.rb b/app/helpers/cycle_analytics_helper.rb index c49c51642ed..d397b02a3aa 100644 --- a/app/helpers/cycle_analytics_helper.rb +++ b/app/helpers/cycle_analytics_helper.rb @@ -10,15 +10,28 @@ module CycleAnalyticsHelper [: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] = { + 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: distance_of_time_in_words(cycle_analytics.send(stage_method)) + value: value ? distance_of_time_in_words(value) : nil } - hash + stats end - { stats: stats } + 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 |