Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-04-20 21:38:24 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-04-20 21:38:24 +0300
commit983a0bba5d2a042c4a3bbb22432ec192c7501d82 (patch)
treeb153cd387c14ba23bd5a07514c7c01fddf6a78a0 /lib/gitlab/cycle_analytics
parenta2bddee2cdb38673df0e004d5b32d9f77797de64 (diff)
Add latest changes from gitlab-org/gitlab@12-10-stable-ee
Diffstat (limited to 'lib/gitlab/cycle_analytics')
-rw-r--r--lib/gitlab/cycle_analytics/group_stage_summary.rb36
-rw-r--r--lib/gitlab/cycle_analytics/stage_summary.rb23
-rw-r--r--lib/gitlab/cycle_analytics/summary/deployment_frequency.rb30
-rw-r--r--lib/gitlab/cycle_analytics/summary/group/deployment_frequency.rb33
-rw-r--r--lib/gitlab/cycle_analytics/summary_helper.rb18
5 files changed, 133 insertions, 7 deletions
diff --git a/lib/gitlab/cycle_analytics/group_stage_summary.rb b/lib/gitlab/cycle_analytics/group_stage_summary.rb
index 26eaaf7df83..09b33d01846 100644
--- a/lib/gitlab/cycle_analytics/group_stage_summary.rb
+++ b/lib/gitlab/cycle_analytics/group_stage_summary.rb
@@ -12,14 +12,42 @@ module Gitlab
end
def data
- [serialize(Summary::Group::Issue.new(group: group, current_user: current_user, options: options)),
- serialize(Summary::Group::Deploy.new(group: group, options: options))]
+ [issue_stats,
+ deploy_stats,
+ deployment_frequency_stats]
end
private
- def serialize(summary_object)
- AnalyticsSummarySerializer.new.represent(summary_object)
+ def issue_stats
+ serialize(
+ Summary::Group::Issue.new(
+ group: group, current_user: current_user, options: options)
+ )
+ end
+
+ def deployments_summary
+ @deployments_summary ||=
+ Summary::Group::Deploy.new(group: group, options: options)
+ end
+
+ def deploy_stats
+ serialize deployments_summary
+ end
+
+ def deployment_frequency_stats
+ serialize(
+ Summary::Group::DeploymentFrequency.new(
+ deployments: deployments_summary.value,
+ group: group,
+ options: options),
+ with_unit: true
+ )
+ end
+
+ 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/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/group/deployment_frequency.rb b/lib/gitlab/cycle_analytics/summary/group/deployment_frequency.rb
new file mode 100644
index 00000000000..9fbbbb5a1ec
--- /dev/null
+++ b/lib/gitlab/cycle_analytics/summary/group/deployment_frequency.rb
@@ -0,0 +1,33 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module CycleAnalytics
+ module Summary
+ module Group
+ class DeploymentFrequency < Group::Base
+ include GroupProjectsProvider
+ include SummaryHelper
+
+ def initialize(deployments:, group:, options:)
+ @deployments = deployments
+
+ super(group: group, options: options)
+ end
+
+ def title
+ _('Deployment Frequency')
+ end
+
+ def value
+ @value ||=
+ frequency(@deployments, options[:from], options[:to] || Time.now)
+ end
+
+ def unit
+ _('per day')
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/lib/gitlab/cycle_analytics/summary_helper.rb b/lib/gitlab/cycle_analytics/summary_helper.rb
new file mode 100644
index 00000000000..06abcd151d4
--- /dev/null
+++ b/lib/gitlab/cycle_analytics/summary_helper.rb
@@ -0,0 +1,18 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module CycleAnalytics
+ module SummaryHelper
+ def frequency(count, from, to)
+ 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).fdiv(1.day), 1].max
+ end
+ end
+ end
+end