Commit 4531e433 authored by Timothy Andrew's avatar Timothy Andrew

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.
parent 2cddd02e
......@@ -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
......@@ -4,6 +4,11 @@ class CycleAnalytics
def initialize(project, from:)
@project = project
@from = from
@summary = Summary.new(project, from: from)
end
def summary
@summary
end
def issue
......
class CycleAnalytics
class Summary
def initialize(project, from:)
@project = project
@from = from
end
def new_issues
@project.issues.where("created_at > ?", @from).count
end
def commits
repository = @project.repository.raw_repository
repository.log(ref: @project.default_branch, after: @from).count
end
def deploys
@project.deployments.count
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment