diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-21 18:21:10 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-21 18:21:10 +0300 |
commit | e33f87ac0fabaab468ce4b457996cc0f1b1bb648 (patch) | |
tree | 8bf0de72a9acac014cfdaddab7d463b208294af2 /lib/gitlab/cycle_analytics | |
parent | 5baf990db20a75078684702782c24399ef9eb0fa (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/gitlab/cycle_analytics')
-rw-r--r-- | lib/gitlab/cycle_analytics/stage_summary.rb | 23 | ||||
-rw-r--r-- | lib/gitlab/cycle_analytics/summary/deployment_frequency.rb | 30 | ||||
-rw-r--r-- | lib/gitlab/cycle_analytics/summary_helper.rb | 7 |
3 files changed, 55 insertions, 5 deletions
diff --git a/lib/gitlab/cycle_analytics/stage_summary.rb b/lib/gitlab/cycle_analytics/stage_summary.rb index 9c75d4bb455..564feb0319f 100644 --- a/lib/gitlab/cycle_analytics/stage_summary.rb +++ b/lib/gitlab/cycle_analytics/stage_summary.rb @@ -14,6 +14,7 @@ module Gitlab summary = [issue_stats] summary << commit_stats if user_has_sufficient_access? summary << deploy_stats + summary << deployment_frequency_stats end private @@ -26,16 +27,32 @@ module Gitlab serialize(Summary::Commit.new(project: @project, from: @from, to: @to)) end + def deployments_summary + @deployments_summary ||= + Summary::Deploy.new(project: @project, from: @from, to: @to) + end + def deploy_stats - serialize(Summary::Deploy.new(project: @project, from: @from, to: @to)) + serialize deployments_summary + end + + def deployment_frequency_stats + serialize( + Summary::DeploymentFrequency.new( + deployments: deployments_summary.value, + from: @from, + to: @to), + with_unit: true + ) end def user_has_sufficient_access? @project.team.member?(@current_user, Gitlab::Access::REPORTER) end - def serialize(summary_object) - AnalyticsSummarySerializer.new.represent(summary_object) + def serialize(summary_object, with_unit: false) + AnalyticsSummarySerializer.new.represent( + summary_object, with_unit: with_unit) end end end diff --git a/lib/gitlab/cycle_analytics/summary/deployment_frequency.rb b/lib/gitlab/cycle_analytics/summary/deployment_frequency.rb new file mode 100644 index 00000000000..436dc91bd6b --- /dev/null +++ b/lib/gitlab/cycle_analytics/summary/deployment_frequency.rb @@ -0,0 +1,30 @@ +# frozen_string_literal: true + +module Gitlab + module CycleAnalytics + module Summary + class DeploymentFrequency < Base + include SummaryHelper + + def initialize(deployments:, from:, to: nil, project: nil) + @deployments = deployments + + super(project: project, from: from, to: to) + end + + def title + _('Deployment Frequency') + end + + def value + @value ||= + frequency(@deployments, @from, @to || Time.now) + end + + def unit + _('per day') + end + end + end + end +end diff --git a/lib/gitlab/cycle_analytics/summary_helper.rb b/lib/gitlab/cycle_analytics/summary_helper.rb index 2eb8f2b2664..06abcd151d4 100644 --- a/lib/gitlab/cycle_analytics/summary_helper.rb +++ b/lib/gitlab/cycle_analytics/summary_helper.rb @@ -4,11 +4,14 @@ module Gitlab module CycleAnalytics module SummaryHelper def frequency(count, from, to) - (count / days(from, to)).round(1) + return count if count.zero? + + freq = (count / days(from, to)).round(1) + freq.zero? ? '0' : freq end def days(from, to) - [(to.end_of_day - from.beginning_of_day) / (24 * 60 * 60), 1].max + [(to.end_of_day - from.beginning_of_day).fdiv(1.day), 1].max end end end |