diff options
author | Timothy Andrew <mail@timothyandrew.net> | 2016-09-19 15:00:55 +0530 |
---|---|---|
committer | Timothy Andrew <mail@timothyandrew.net> | 2016-09-19 15:00:55 +0530 |
commit | 4531e433ad33e67cb66abaa4626b5e608eb11f11 (patch) | |
tree | e2199500817186477599b226f32d5acb778a2cc0 | |
parent | 2cddd02ec5dd9d27fc9e9b6ac5e0748fe92e1cff (diff) | |
download | gitlab-ce-4531e433ad33e67cb66abaa4626b5e608eb11f11.tar.gz |
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.
-rw-r--r-- | app/helpers/cycle_analytics_helper.rb | 23 | ||||
-rw-r--r-- | app/models/cycle_analytics.rb | 5 | ||||
-rw-r--r-- | app/models/cycle_analytics/summary.rb | 21 |
3 files changed, 44 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 diff --git a/app/models/cycle_analytics.rb b/app/models/cycle_analytics.rb index 5f09e5d611b..d4f682c4a33 100644 --- a/app/models/cycle_analytics.rb +++ b/app/models/cycle_analytics.rb @@ -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 diff --git a/app/models/cycle_analytics/summary.rb b/app/models/cycle_analytics/summary.rb new file mode 100644 index 00000000000..2fa94f8c18c --- /dev/null +++ b/app/models/cycle_analytics/summary.rb @@ -0,0 +1,21 @@ +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 |