Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
57fb55f2
Commit
57fb55f2
authored
May 07, 2020
by
Adam Hegyi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor VSA summary value formatting
Move out VSA summary value formatting from the serializer
parent
26e53150
Changes
13
Show whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
113 additions
and
32 deletions
+113
-32
app/serializers/analytics_summary_entity.rb
app/serializers/analytics_summary_entity.rb
+1
-3
ee/lib/gitlab/analytics/cycle_analytics/summary/group/base_time.rb
...tlab/analytics/cycle_analytics/summary/group/base_time.rb
+1
-1
ee/lib/gitlab/analytics/cycle_analytics/summary/group/deploy.rb
.../gitlab/analytics/cycle_analytics/summary/group/deploy.rb
+9
-7
ee/lib/gitlab/analytics/cycle_analytics/summary/group/issue.rb
...b/gitlab/analytics/cycle_analytics/summary/group/issue.rb
+2
-2
ee/lib/gitlab/analytics/cycle_analytics/summary/group/stage_summary.rb
.../analytics/cycle_analytics/summary/group/stage_summary.rb
+1
-1
lib/gitlab/cycle_analytics/stage_summary.rb
lib/gitlab/cycle_analytics/stage_summary.rb
+2
-3
lib/gitlab/cycle_analytics/summary/commit.rb
lib/gitlab/cycle_analytics/summary/commit.rb
+3
-3
lib/gitlab/cycle_analytics/summary/deploy.rb
lib/gitlab/cycle_analytics/summary/deploy.rb
+9
-7
lib/gitlab/cycle_analytics/summary/deployment_frequency.rb
lib/gitlab/cycle_analytics/summary/deployment_frequency.rb
+1
-2
lib/gitlab/cycle_analytics/summary/issue.rb
lib/gitlab/cycle_analytics/summary/issue.rb
+10
-1
lib/gitlab/cycle_analytics/summary/value.rb
lib/gitlab/cycle_analytics/summary/value.rb
+42
-0
lib/gitlab/cycle_analytics/summary_helper.rb
lib/gitlab/cycle_analytics/summary_helper.rb
+3
-2
spec/lib/gitlab/cycle_analytics/summary/value_spec.rb
spec/lib/gitlab/cycle_analytics/summary/value_spec.rb
+29
-0
No files found.
app/serializers/analytics_summary_entity.rb
View file @
57fb55f2
...
...
@@ -8,8 +8,6 @@ class AnalyticsSummaryEntity < Grape::Entity
private
def
value
return
object
.
value
if
object
.
value
.
is_a?
String
object
.
value
&
.
nonzero?
?
object
.
value
.
to_s
:
'-'
object
.
value
.
to_s
end
end
ee/lib/gitlab/analytics/cycle_analytics/summary/group/base_time.rb
View file @
57fb55f2
...
...
@@ -13,7 +13,7 @@ module Gitlab
end
def
value
@value
||=
data_collector
.
median
.
days
&
.
round
(
1
)
@value
||=
Gitlab
::
CycleAnalytics
::
Summary
::
Value
::
PrettyNumeric
.
new
(
data_collector
.
median
.
days
&
.
round
(
1
)
)
end
def
unit
...
...
ee/lib/gitlab/analytics/cycle_analytics/summary/group/deploy.rb
View file @
57fb55f2
...
...
@@ -13,19 +13,21 @@ module Gitlab
end
def
value
@value
||=
find_deployments
@value
||=
::
Gitlab
::
CycleAnalytics
::
Summary
::
Value
::
PrettyNumeric
.
new
(
deployments_count
)
end
private
# rubocop: disable CodeReuse/ActiveRecord
def
find_deployments
def
deployments_count
@deployments_count
||=
begin
deployments
=
Deployment
.
joins
(
:project
).
merge
(
Project
.
inside_path
(
group
.
full_path
))
deployments
=
deployments
.
where
(
projects:
{
id:
options
[
:projects
]
})
if
options
[
:projects
]
deployments
=
deployments
.
where
(
"deployments.created_at > ?"
,
options
[
:from
])
deployments
=
deployments
.
where
(
"deployments.created_at < ?"
,
options
[
:to
])
if
options
[
:to
]
deployments
.
success
.
count
end
end
# rubocop: enable CodeReuse/ActiveRecord
end
end
...
...
ee/lib/gitlab/analytics/cycle_analytics/summary/group/issue.rb
View file @
57fb55f2
...
...
@@ -19,13 +19,13 @@ module Gitlab
end
def
value
@value
||=
find_issues
@value
||=
::
Gitlab
::
CycleAnalytics
::
Summary
::
Value
::
PrettyNumeric
.
new
(
issues_count
)
end
private
# rubocop: disable CodeReuse/ActiveRecord
def
find_issues
def
issues_count
issues
=
IssuesFinder
.
new
(
current_user
,
finder_params
).
execute
issues
=
issues
.
where
(
projects:
{
id:
options
[
:projects
]
})
if
options
[
:projects
]
issues
.
count
...
...
ee/lib/gitlab/analytics/cycle_analytics/summary/group/stage_summary.rb
View file @
57fb55f2
...
...
@@ -41,7 +41,7 @@ module Gitlab
def
deployment_frequency_stats
serialize
(
Summary
::
Group
::
DeploymentFrequency
.
new
(
deployments:
deployments_summary
.
value
,
deployments:
deployments_summary
.
value
.
raw_value
,
group:
group
,
options:
options
),
with_unit:
true
...
...
lib/gitlab/cycle_analytics/stage_summary.rb
View file @
57fb55f2
...
...
@@ -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
...
...
lib/gitlab/cycle_analytics/summary/commit.rb
View file @
57fb55f2
...
...
@@ -9,7 +9,7 @@ module Gitlab
end
def
value
@value
||=
co
unt_commits
@value
||=
co
mmits_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
co
unt_commits
def
co
mmits_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
...
...
lib/gitlab/cycle_analytics/summary/deploy.rb
View file @
57fb55f2
...
...
@@ -4,14 +4,17 @@ 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
@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
...
...
@@ -19,5 +22,4 @@ module Gitlab
end
end
end
end
end
lib/gitlab/cycle_analytics/summary/deployment_frequency.rb
View file @
57fb55f2
...
...
@@ -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
...
...
lib/gitlab/cycle_analytics/summary/issue.rb
View file @
57fb55f2
...
...
@@ -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
...
...
lib/gitlab/cycle_analytics/summary/value.rb
0 → 100644
View file @
57fb55f2
# 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
lib/gitlab/cycle_analytics/summary_helper.rb
View file @
57fb55f2
...
...
@@ -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
)
...
...
spec/lib/gitlab/cycle_analytics/summary/value_spec.rb
0 → 100644
View file @
57fb55f2
# frozen_string_literal: true
require
'spec_helper'
describe
Gitlab
::
CycleAnalytics
::
Summary
::
Value
do
describe
Gitlab
::
CycleAnalytics
::
Summary
::
Value
::
None
do
it
'returns `-`'
do
expect
(
described_class
.
new
.
to_s
).
to
eq
(
'-'
)
end
end
describe
Gitlab
::
CycleAnalytics
::
Summary
::
Value
::
Numeric
do
it
'returns the string representation of the number'
do
expect
(
described_class
.
new
(
3.2
).
to_s
).
to
eq
(
'3.2'
)
end
end
describe
Gitlab
::
CycleAnalytics
::
Summary
::
Value
::
PrettyNumeric
do
describe
'#to_s'
do
it
'returns `-` when the number is 0'
do
expect
(
described_class
.
new
(
0
).
to_s
).
to
eq
(
'-'
)
end
it
'returns the string representation of the number'
do
expect
(
described_class
.
new
(
100
).
to_s
).
to
eq
(
'100'
)
end
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment