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
0
Merge Requests
0
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
Jérome Perrin
gitlab-ce
Commits
02e1e481
Commit
02e1e481
authored
Nov 22, 2016
by
James Lopez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
more refactoring and fixing old specs
parent
8639ea1b
Changes
14
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
50 additions
and
49 deletions
+50
-49
app/controllers/concerns/cycle_analytics_params.rb
app/controllers/concerns/cycle_analytics_params.rb
+4
-0
app/controllers/projects/cycle_analytics/events_controller.rb
...controllers/projects/cycle_analytics/events_controller.rb
+0
-4
app/controllers/projects/cycle_analytics_controller.rb
app/controllers/projects/cycle_analytics_controller.rb
+5
-3
app/models/cycle_analytics.rb
app/models/cycle_analytics.rb
+16
-10
lib/gitlab/cycle_analytics/summary.rb
lib/gitlab/cycle_analytics/summary.rb
+3
-15
spec/models/cycle_analytics/code_spec.rb
spec/models/cycle_analytics/code_spec.rb
+9
-9
spec/models/cycle_analytics/issue_spec.rb
spec/models/cycle_analytics/issue_spec.rb
+1
-1
spec/models/cycle_analytics/plan_spec.rb
spec/models/cycle_analytics/plan_spec.rb
+1
-1
spec/models/cycle_analytics/production_spec.rb
spec/models/cycle_analytics/production_spec.rb
+1
-1
spec/models/cycle_analytics/review_spec.rb
spec/models/cycle_analytics/review_spec.rb
+1
-1
spec/models/cycle_analytics/staging_spec.rb
spec/models/cycle_analytics/staging_spec.rb
+1
-1
spec/models/cycle_analytics/summary_spec.rb
spec/models/cycle_analytics/summary_spec.rb
+1
-1
spec/models/cycle_analytics/test_spec.rb
spec/models/cycle_analytics/test_spec.rb
+1
-1
spec/support/cycle_analytics_helpers/test_generation.rb
spec/support/cycle_analytics_helpers/test_generation.rb
+6
-1
No files found.
app/controllers/concerns/cycle_analytics_params.rb
View file @
02e1e481
module
CycleAnalyticsParams
extend
ActiveSupport
::
Concern
def
options
@options
||=
{
from:
start_date
(
events_params
),
current_user:
current_user
}
end
def
start_date
(
params
)
params
[
:start_date
]
==
'30'
?
30
.
days
.
ago
:
90
.
days
.
ago
end
...
...
app/controllers/projects/cycle_analytics/events_controller.rb
View file @
02e1e481
...
...
@@ -51,10 +51,6 @@ module Projects
@events
||=
Gitlab
::
CycleAnalytics
::
Events
.
new
(
project:
project
,
options:
options
)
end
def
options
@options
||=
{
from:
start_date
(
events_params
),
current_user:
current_user
}
end
def
events_params
return
{}
unless
params
[
:events
].
present?
...
...
app/controllers/projects/cycle_analytics_controller.rb
View file @
02e1e481
...
...
@@ -6,7 +6,9 @@ class Projects::CycleAnalyticsController < Projects::ApplicationController
before_action
:authorize_read_cycle_analytics!
def
show
@cycle_analytics
=
::
CycleAnalytics
.
new
(
@project
,
current_user
,
from:
start_date
(
cycle_analytics_params
))
@cycle_analytics
=
::
CycleAnalytics
.
new
(
@project
,
options:
options
)
@cycle_analytics_no_data
=
@cycle_analytics
.
no_stats?
respond_to
do
|
format
|
format
.
html
...
...
@@ -25,8 +27,8 @@ class Projects::CycleAnalyticsController < Projects::ApplicationController
def
cycle_analytics_json
{
summary:
@cycle_analytics
.
summary
,
stats:
nil
,
# TODO
permissions:
@cycle_analytics
.
permissions
(
user:
current_user
)
# TODO
stats:
@cycle_analytics
.
stats
,
permissions:
@cycle_analytics
.
permissions
(
user:
current_user
)
}
end
end
app/models/cycle_analytics.rb
View file @
02e1e481
class
CycleAnalytics
STAGES
=
%i[issue plan code test review staging production]
.
freeze
def
initialize
(
project
,
from
:)
def
initialize
(
project
,
options
:)
@project
=
project
@options
=
options
end
...
...
@@ -10,22 +10,28 @@ class CycleAnalytics
@summary
||=
Gitlab
::
CycleAnalytics
::
Summary
.
new
(
@project
,
from:
@options
[
:from
]).
data
end
def
method_missing
(
method_sym
,
*
arguments
,
&
block
)
classify_stage
(
method_sym
).
new
(
project:
@project
,
options:
@options
,
stage:
method_sym
)
def
stats
@stats
||=
stats_per_stage
end
def
no_stats?
stats
.
map
(
&
:value
).
compact
.
empty?
end
def
permissions
(
user
:)
Gitlab
::
CycleAnalytics
::
Permissions
.
get
(
user:
user
,
project:
@project
)
end
def
issue
@fetcher
.
calculate_metric
(
:issue
,
Issue
.
arel_table
[
:created_at
],
[
Issue
::
Metrics
.
arel_table
[
:first_associated_with_milestone_at
],
Issue
::
Metrics
.
arel_table
[
:first_added_to_board_at
]])
private
def
stats_per_stage
STAGES
.
map
do
|
stage_name
|
classify_stage
(
method_sym
).
new
(
project:
@project
,
options:
@options
,
stage:
stage_name
).
median_data
end
end
def
classify_stage
(
method_sym
)
"Gitlab::CycleAnalytics::
#{
method_sym
.
to_s
.
capitalize
}
Stage"
.
constantize
def
classify_stage
(
stage_name
)
"Gitlab::CycleAnalytics::
#{
stage_name
.
to_s
.
capitalize
}
Stage"
.
constantize
end
end
lib/gitlab/cycle_analytics/summary.rb
View file @
02e1e481
...
...
@@ -9,9 +9,9 @@ module Gitlab
end
def
data
[
serialize
(
issue
),
serialize
(
commit
),
serialize
(
deploy
)]
[
serialize
(
Summary
::
Issue
.
new
(
project:
@project
,
from:
@from
)
),
serialize
(
Summary
::
Commit
.
new
(
project:
@project
,
from:
@from
)
),
serialize
(
Summary
::
Deploy
.
new
(
project:
@project
,
from:
@from
)
)]
end
private
...
...
@@ -19,18 +19,6 @@ module Gitlab
def
serialize
(
summary_object
)
AnalyticsSummarySerializer
.
new
.
represent
(
summary_object
).
as_json
end
def
issue
Summary
::
Issue
.
new
(
project:
@project
,
from:
@from
)
end
def
deploy
Summary
::
Deploy
.
new
(
project:
@project
,
from:
@from
)
end
def
commit
Summary
::
Commit
.
new
(
project:
@project
,
from:
@from
)
end
end
end
end
spec/models/cycle_analytics/code_spec.rb
View file @
02e1e481
...
...
@@ -6,7 +6,7 @@ describe 'CycleAnalytics#code', feature: true do
let
(
:project
)
{
create
(
:project
)
}
let
(
:from_date
)
{
10
.
days
.
ago
}
let
(
:user
)
{
create
(
:user
,
:admin
)
}
subject
{
CycleAnalytics
.
new
(
project
,
user
,
from:
from_date
)
}
subject
{
CycleAnalytics
Test
.
new
(
project
,
options:
{
from:
from_date
}
)
}
context
'with deployment'
do
generate_cycle_analytics_spec
(
...
...
@@ -16,10 +16,10 @@ describe 'CycleAnalytics#code', feature: true do
->
(
context
,
data
)
do
context
.
create_commit_referencing_issue
(
data
[
:issue
])
end
]],
end_time_conditions:
[[
"merge request that closes issue is created"
,
->
(
context
,
data
)
do
context
.
create_merge_request_closing_issue
(
data
[
:issue
])
end
]],
end_time_conditions:
[[
"merge request that closes issue is created"
,
->
(
context
,
data
)
do
context
.
create_merge_request_closing_issue
(
data
[
:issue
])
end
]],
post_fn:
->
(
context
,
data
)
do
context
.
merge_merge_requests_closing_issue
(
data
[
:issue
])
context
.
deploy_master
...
...
@@ -50,10 +50,10 @@ describe 'CycleAnalytics#code', feature: true do
->
(
context
,
data
)
do
context
.
create_commit_referencing_issue
(
data
[
:issue
])
end
]],
end_time_conditions:
[[
"merge request that closes issue is created"
,
->
(
context
,
data
)
do
context
.
create_merge_request_closing_issue
(
data
[
:issue
])
end
]],
end_time_conditions:
[[
"merge request that closes issue is created"
,
->
(
context
,
data
)
do
context
.
create_merge_request_closing_issue
(
data
[
:issue
])
end
]],
post_fn:
->
(
context
,
data
)
do
context
.
merge_merge_requests_closing_issue
(
data
[
:issue
])
end
)
...
...
spec/models/cycle_analytics/issue_spec.rb
View file @
02e1e481
...
...
@@ -6,7 +6,7 @@ describe 'CycleAnalytics#issue', models: true do
let
(
:project
)
{
create
(
:project
)
}
let
(
:from_date
)
{
10
.
days
.
ago
}
let
(
:user
)
{
create
(
:user
,
:admin
)
}
subject
{
CycleAnalytics
.
new
(
project
,
user
,
from:
from_date
)
}
subject
{
CycleAnalytics
Test
.
new
(
project
,
options:
{
from:
from_date
}
)
}
generate_cycle_analytics_spec
(
phase: :issue
,
...
...
spec/models/cycle_analytics/plan_spec.rb
View file @
02e1e481
...
...
@@ -6,7 +6,7 @@ describe 'CycleAnalytics#plan', feature: true do
let
(
:project
)
{
create
(
:project
)
}
let
(
:from_date
)
{
10
.
days
.
ago
}
let
(
:user
)
{
create
(
:user
,
:admin
)
}
subject
{
CycleAnalytics
.
new
(
project
,
user
,
from:
from_date
)
}
subject
{
CycleAnalytics
Test
.
new
(
project
,
options:
{
from:
from_date
}
)
}
generate_cycle_analytics_spec
(
phase: :plan
,
...
...
spec/models/cycle_analytics/production_spec.rb
View file @
02e1e481
...
...
@@ -6,7 +6,7 @@ describe 'CycleAnalytics#production', feature: true do
let
(
:project
)
{
create
(
:project
)
}
let
(
:from_date
)
{
10
.
days
.
ago
}
let
(
:user
)
{
create
(
:user
,
:admin
)
}
subject
{
CycleAnalytics
.
new
(
project
,
user
,
from:
from_date
)
}
subject
{
CycleAnalytics
Test
.
new
(
project
,
options:
{
from:
from_date
}
)
}
generate_cycle_analytics_spec
(
phase: :production
,
...
...
spec/models/cycle_analytics/review_spec.rb
View file @
02e1e481
...
...
@@ -6,7 +6,7 @@ describe 'CycleAnalytics#review', feature: true do
let
(
:project
)
{
create
(
:project
)
}
let
(
:from_date
)
{
10
.
days
.
ago
}
let
(
:user
)
{
create
(
:user
,
:admin
)
}
subject
{
CycleAnalytics
.
new
(
project
,
user
,
from:
from_date
)
}
subject
{
CycleAnalytics
Test
.
new
(
project
,
options:
{
from:
from_date
}
)
}
generate_cycle_analytics_spec
(
phase: :review
,
...
...
spec/models/cycle_analytics/staging_spec.rb
View file @
02e1e481
...
...
@@ -6,7 +6,7 @@ describe 'CycleAnalytics#staging', feature: true do
let
(
:project
)
{
create
(
:project
)
}
let
(
:from_date
)
{
10
.
days
.
ago
}
let
(
:user
)
{
create
(
:user
,
:admin
)
}
subject
{
CycleAnalytics
.
new
(
project
,
user
,
from:
from_date
)
}
subject
{
CycleAnalytics
Test
.
new
(
project
,
options:
{
from:
from_date
}
)
}
generate_cycle_analytics_spec
(
phase: :staging
,
...
...
spec/models/cycle_analytics/summary_spec.rb
View file @
02e1e481
...
...
@@ -4,7 +4,7 @@ describe CycleAnalytics::Summary, models: true do
let
(
:project
)
{
create
(
:project
)
}
let
(
:from
)
{
Time
.
now
}
let
(
:user
)
{
create
(
:user
,
:admin
)
}
subject
{
described_class
.
new
(
project
,
user
,
from:
from
)
}
subject
{
CycleAnalyticsTest
.
new
(
project
,
options:
{
from:
from_date
}
)
}
describe
"#new_issues"
do
it
"finds the number of issues created after the 'from date'"
do
...
...
spec/models/cycle_analytics/test_spec.rb
View file @
02e1e481
...
...
@@ -6,7 +6,7 @@ describe 'CycleAnalytics#test', feature: true do
let
(
:project
)
{
create
(
:project
)
}
let
(
:from_date
)
{
10
.
days
.
ago
}
let
(
:user
)
{
create
(
:user
,
:admin
)
}
subject
{
CycleAnalytics
.
new
(
project
,
user
,
from:
from_date
)
}
subject
{
CycleAnalytics
Test
.
new
(
project
,
options:
{
from:
from_date
}
)
}
generate_cycle_analytics_spec
(
phase: :test
,
...
...
spec/support/cycle_analytics_helpers/test_generation.rb
View file @
02e1e481
class
CycleAnalyticsTest
<
CycleAnalytics
def
method_missing
(
method_sym
,
*
arguments
,
&
block
)
classify_stage
(
method_sym
).
new
(
project:
@project
,
options:
@options
,
stage:
method_sym
).
median
end
end
# rubocop:disable Metrics/AbcSize
# Note: The ABC size is large here because we have a method generating test cases with
# multiple nested contexts. This shouldn't count as a violation.
module
CycleAnalyticsHelpers
module
TestGeneration
# Generate the most common set of specs that all cycle analytics phases need to have.
...
...
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