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-05-12 18:10:33 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-05-12 18:10:33 +0300
commit8ff63012e9b7e3dc2279e636868af9a438d1fa93 (patch)
tree4dd67f247345cbc2e8629c4a5f2b935dafc988e3 /lib/gitlab/cycle_analytics
parentef7cfec30c9fab7b9e757877c472ca7ca2eccc2d (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.rb5
-rw-r--r--lib/gitlab/cycle_analytics/summary/commit.rb6
-rw-r--r--lib/gitlab/cycle_analytics/summary/deploy.rb16
-rw-r--r--lib/gitlab/cycle_analytics/summary/deployment_frequency.rb3
-rw-r--r--lib/gitlab/cycle_analytics/summary/issue.rb11
-rw-r--r--lib/gitlab/cycle_analytics/summary/value.rb42
-rw-r--r--lib/gitlab/cycle_analytics/summary_helper.rb5
7 files changed, 70 insertions, 18 deletions
diff --git a/lib/gitlab/cycle_analytics/stage_summary.rb b/lib/gitlab/cycle_analytics/stage_summary.rb
index 564feb0319f..7559cd376bf 100644
--- a/lib/gitlab/cycle_analytics/stage_summary.rb
+++ b/lib/gitlab/cycle_analytics/stage_summary.rb
@@ -28,8 +28,7 @@ module Gitlab
end
def deployments_summary
- @deployments_summary ||=
- Summary::Deploy.new(project: @project, from: @from, to: @to)
+ @deployments_summary ||= Summary::Deploy.new(project: @project, from: @from, to: @to)
end
def deploy_stats
@@ -39,7 +38,7 @@ module Gitlab
def deployment_frequency_stats
serialize(
Summary::DeploymentFrequency.new(
- deployments: deployments_summary.value,
+ deployments: deployments_summary.value.raw_value,
from: @from,
to: @to),
with_unit: true
diff --git a/lib/gitlab/cycle_analytics/summary/commit.rb b/lib/gitlab/cycle_analytics/summary/commit.rb
index 76049c6b742..1f426b81800 100644
--- a/lib/gitlab/cycle_analytics/summary/commit.rb
+++ b/lib/gitlab/cycle_analytics/summary/commit.rb
@@ -9,7 +9,7 @@ module Gitlab
end
def value
- @value ||= count_commits
+ @value ||= commits_count ? Value::PrettyNumeric.new(commits_count) : Value::None.new
end
private
@@ -18,10 +18,10 @@ module Gitlab
# a limit. Since we need a commit count, we _can't_ enforce a limit, so
# the easiest way forward is to replicate the relevant portions of the
# `log` function here.
- def count_commits
+ def commits_count
return unless ref
- gitaly_commit_client.commit_count(ref, after: @from, before: @to)
+ @commits_count ||= gitaly_commit_client.commit_count(ref, after: @from, before: @to)
end
def gitaly_commit_client
diff --git a/lib/gitlab/cycle_analytics/summary/deploy.rb b/lib/gitlab/cycle_analytics/summary/deploy.rb
index 5ff8d881143..8544ea1a91e 100644
--- a/lib/gitlab/cycle_analytics/summary/deploy.rb
+++ b/lib/gitlab/cycle_analytics/summary/deploy.rb
@@ -4,18 +4,20 @@ module Gitlab
module CycleAnalytics
module Summary
class Deploy < Base
- include Gitlab::Utils::StrongMemoize
-
def title
n_('Deploy', 'Deploys', value)
end
def value
- strong_memoize(:value) do
- query = @project.deployments.success.where("created_at >= ?", @from)
- query = query.where("created_at <= ?", @to) if @to
- query.count
- end
+ @value ||= Value::PrettyNumeric.new(deployments_count)
+ end
+
+ private
+
+ def deployments_count
+ query = @project.deployments.success.where("created_at >= ?", @from)
+ query = query.where("created_at <= ?", @to) if @to
+ query.count
end
end
end
diff --git a/lib/gitlab/cycle_analytics/summary/deployment_frequency.rb b/lib/gitlab/cycle_analytics/summary/deployment_frequency.rb
index 436dc91bd6b..00676a02a6f 100644
--- a/lib/gitlab/cycle_analytics/summary/deployment_frequency.rb
+++ b/lib/gitlab/cycle_analytics/summary/deployment_frequency.rb
@@ -17,8 +17,7 @@ module Gitlab
end
def value
- @value ||=
- frequency(@deployments, @from, @to || Time.now)
+ @value ||= frequency(@deployments, @from, @to || Time.now)
end
def unit
diff --git a/lib/gitlab/cycle_analytics/summary/issue.rb b/lib/gitlab/cycle_analytics/summary/issue.rb
index 52892eb5a1a..ce7788590b9 100644
--- a/lib/gitlab/cycle_analytics/summary/issue.rb
+++ b/lib/gitlab/cycle_analytics/summary/issue.rb
@@ -16,7 +16,16 @@ module Gitlab
end
def value
- @value ||= IssuesFinder.new(@current_user, project_id: @project.id, created_after: @from, created_before: @to).execute.count
+ @value ||= Value::PrettyNumeric.new(issues_count)
+ end
+
+ private
+
+ def issues_count
+ IssuesFinder
+ .new(@current_user, project_id: @project.id, created_after: @from, created_before: @to)
+ .execute
+ .count
end
end
end
diff --git a/lib/gitlab/cycle_analytics/summary/value.rb b/lib/gitlab/cycle_analytics/summary/value.rb
new file mode 100644
index 00000000000..9516f9ec974
--- /dev/null
+++ b/lib/gitlab/cycle_analytics/summary/value.rb
@@ -0,0 +1,42 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module CycleAnalytics
+ module Summary
+ class Value
+ attr_reader :value
+
+ def raw_value
+ value
+ end
+
+ def to_s
+ raise NotImplementedError
+ end
+
+ class None < self
+ def to_s
+ '-'
+ end
+ end
+
+ class Numeric < self
+ def initialize(value)
+ @value = value
+ end
+
+ def to_s
+ value.zero? ? '0' : value.to_s
+ end
+ end
+
+ class PrettyNumeric < Numeric
+ def to_s
+ # 0 is shown as -
+ value.nonzero? ? super : None.new.to_s
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/lib/gitlab/cycle_analytics/summary_helper.rb b/lib/gitlab/cycle_analytics/summary_helper.rb
index 06abcd151d4..3cf9f463024 100644
--- a/lib/gitlab/cycle_analytics/summary_helper.rb
+++ b/lib/gitlab/cycle_analytics/summary_helper.rb
@@ -4,10 +4,11 @@ module Gitlab
module CycleAnalytics
module SummaryHelper
def frequency(count, from, to)
- return count if count.zero?
+ return Summary::Value::None.new if count.zero?
freq = (count / days(from, to)).round(1)
- freq.zero? ? '0' : freq
+
+ Summary::Value::Numeric.new(freq)
end
def days(from, to)