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
module
CycleAnalyticsParams
extend
ActiveSupport
::
Concern
extend
ActiveSupport
::
Concern
def
options
@options
||=
{
from:
start_date
(
events_params
),
current_user:
current_user
}
end
def
start_date
(
params
)
def
start_date
(
params
)
params
[
:start_date
]
==
'30'
?
30
.
days
.
ago
:
90
.
days
.
ago
params
[
:start_date
]
==
'30'
?
30
.
days
.
ago
:
90
.
days
.
ago
end
end
...
...
app/controllers/projects/cycle_analytics/events_controller.rb
View file @
02e1e481
...
@@ -51,10 +51,6 @@ module Projects
...
@@ -51,10 +51,6 @@ module Projects
@events
||=
Gitlab
::
CycleAnalytics
::
Events
.
new
(
project:
project
,
options:
options
)
@events
||=
Gitlab
::
CycleAnalytics
::
Events
.
new
(
project:
project
,
options:
options
)
end
end
def
options
@options
||=
{
from:
start_date
(
events_params
),
current_user:
current_user
}
end
def
events_params
def
events_params
return
{}
unless
params
[
:events
].
present?
return
{}
unless
params
[
:events
].
present?
...
...
app/controllers/projects/cycle_analytics_controller.rb
View file @
02e1e481
...
@@ -6,7 +6,9 @@ class Projects::CycleAnalyticsController < Projects::ApplicationController
...
@@ -6,7 +6,9 @@ class Projects::CycleAnalyticsController < Projects::ApplicationController
before_action
:authorize_read_cycle_analytics!
before_action
:authorize_read_cycle_analytics!
def
show
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
|
respond_to
do
|
format
|
format
.
html
format
.
html
...
@@ -25,8 +27,8 @@ class Projects::CycleAnalyticsController < Projects::ApplicationController
...
@@ -25,8 +27,8 @@ class Projects::CycleAnalyticsController < Projects::ApplicationController
def
cycle_analytics_json
def
cycle_analytics_json
{
{
summary:
@cycle_analytics
.
summary
,
summary:
@cycle_analytics
.
summary
,
stats:
nil
,
# TODO
stats:
@cycle_analytics
.
stats
,
permissions:
@cycle_analytics
.
permissions
(
user:
current_user
)
# TODO
permissions:
@cycle_analytics
.
permissions
(
user:
current_user
)
}
}
end
end
end
end
app/models/cycle_analytics.rb
View file @
02e1e481
class
CycleAnalytics
class
CycleAnalytics
STAGES
=
%i[issue plan code test review staging production]
.
freeze
STAGES
=
%i[issue plan code test review staging production]
.
freeze
def
initialize
(
project
,
from
:)
def
initialize
(
project
,
options
:)
@project
=
project
@project
=
project
@options
=
options
@options
=
options
end
end
...
@@ -10,22 +10,28 @@ class CycleAnalytics
...
@@ -10,22 +10,28 @@ class CycleAnalytics
@summary
||=
Gitlab
::
CycleAnalytics
::
Summary
.
new
(
@project
,
from:
@options
[
:from
]).
data
@summary
||=
Gitlab
::
CycleAnalytics
::
Summary
.
new
(
@project
,
from:
@options
[
:from
]).
data
end
end
def
method_missing
(
method_sym
,
*
arguments
,
&
block
)
def
stats
classify_stage
(
method_sym
).
new
(
project:
@project
,
options:
@options
,
stage:
method_sym
)
@stats
||=
stats_per_stage
end
def
no_stats?
stats
.
map
(
&
:value
).
compact
.
empty?
end
end
def
permissions
(
user
:)
def
permissions
(
user
:)
Gitlab
::
CycleAnalytics
::
Permissions
.
get
(
user:
user
,
project:
@project
)
Gitlab
::
CycleAnalytics
::
Permissions
.
get
(
user:
user
,
project:
@project
)
end
end
def
issue
private
@fetcher
.
calculate_metric
(
:issue
,
Issue
.
arel_table
[
:created_at
],
def
stats_per_stage
[
Issue
::
Metrics
.
arel_table
[
:first_associated_with_milestone_at
],
STAGES
.
map
do
|
stage_name
|
Issue
::
Metrics
.
arel_table
[
:first_added_to_board_at
]])
classify_stage
(
method_sym
).
new
(
project:
@project
,
options:
@options
,
stage:
stage_name
).
median_data
end
end
end
def
classify_stage
(
method_sym
)
def
classify_stage
(
stage_name
)
"Gitlab::CycleAnalytics::
#{
method_sym
.
to_s
.
capitalize
}
Stage"
.
constantize
"Gitlab::CycleAnalytics::
#{
stage_name
.
to_s
.
capitalize
}
Stage"
.
constantize
end
end
end
end
lib/gitlab/cycle_analytics/summary.rb
View file @
02e1e481
...
@@ -9,9 +9,9 @@ module Gitlab
...
@@ -9,9 +9,9 @@ module Gitlab
end
end
def
data
def
data
[
serialize
(
issue
),
[
serialize
(
Summary
::
Issue
.
new
(
project:
@project
,
from:
@from
)
),
serialize
(
commit
),
serialize
(
Summary
::
Commit
.
new
(
project:
@project
,
from:
@from
)
),
serialize
(
deploy
)]
serialize
(
Summary
::
Deploy
.
new
(
project:
@project
,
from:
@from
)
)]
end
end
private
private
...
@@ -19,18 +19,6 @@ module Gitlab
...
@@ -19,18 +19,6 @@ module Gitlab
def
serialize
(
summary_object
)
def
serialize
(
summary_object
)
AnalyticsSummarySerializer
.
new
.
represent
(
summary_object
).
as_json
AnalyticsSummarySerializer
.
new
.
represent
(
summary_object
).
as_json
end
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
end
end
end
spec/models/cycle_analytics/code_spec.rb
View file @
02e1e481
...
@@ -6,7 +6,7 @@ describe 'CycleAnalytics#code', feature: true do
...
@@ -6,7 +6,7 @@ describe 'CycleAnalytics#code', feature: true do
let
(
:project
)
{
create
(
:project
)
}
let
(
:project
)
{
create
(
:project
)
}
let
(
:from_date
)
{
10
.
days
.
ago
}
let
(
:from_date
)
{
10
.
days
.
ago
}
let
(
:user
)
{
create
(
:user
,
:admin
)
}
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
context
'with deployment'
do
generate_cycle_analytics_spec
(
generate_cycle_analytics_spec
(
...
@@ -16,10 +16,10 @@ describe 'CycleAnalytics#code', feature: true do
...
@@ -16,10 +16,10 @@ describe 'CycleAnalytics#code', feature: true do
->
(
context
,
data
)
do
->
(
context
,
data
)
do
context
.
create_commit_referencing_issue
(
data
[
:issue
])
context
.
create_commit_referencing_issue
(
data
[
:issue
])
end
]],
end
]],
end_time_conditions:
[[
"merge request that closes issue is created"
,
end_time_conditions:
[[
"merge request that closes issue is created"
,
->
(
context
,
data
)
do
->
(
context
,
data
)
do
context
.
create_merge_request_closing_issue
(
data
[
:issue
])
context
.
create_merge_request_closing_issue
(
data
[
:issue
])
end
]],
end
]],
post_fn:
->
(
context
,
data
)
do
post_fn:
->
(
context
,
data
)
do
context
.
merge_merge_requests_closing_issue
(
data
[
:issue
])
context
.
merge_merge_requests_closing_issue
(
data
[
:issue
])
context
.
deploy_master
context
.
deploy_master
...
@@ -50,10 +50,10 @@ describe 'CycleAnalytics#code', feature: true do
...
@@ -50,10 +50,10 @@ describe 'CycleAnalytics#code', feature: true do
->
(
context
,
data
)
do
->
(
context
,
data
)
do
context
.
create_commit_referencing_issue
(
data
[
:issue
])
context
.
create_commit_referencing_issue
(
data
[
:issue
])
end
]],
end
]],
end_time_conditions:
[[
"merge request that closes issue is created"
,
end_time_conditions:
[[
"merge request that closes issue is created"
,
->
(
context
,
data
)
do
->
(
context
,
data
)
do
context
.
create_merge_request_closing_issue
(
data
[
:issue
])
context
.
create_merge_request_closing_issue
(
data
[
:issue
])
end
]],
end
]],
post_fn:
->
(
context
,
data
)
do
post_fn:
->
(
context
,
data
)
do
context
.
merge_merge_requests_closing_issue
(
data
[
:issue
])
context
.
merge_merge_requests_closing_issue
(
data
[
:issue
])
end
)
end
)
...
...
spec/models/cycle_analytics/issue_spec.rb
View file @
02e1e481
...
@@ -6,7 +6,7 @@ describe 'CycleAnalytics#issue', models: true do
...
@@ -6,7 +6,7 @@ describe 'CycleAnalytics#issue', models: true do
let
(
:project
)
{
create
(
:project
)
}
let
(
:project
)
{
create
(
:project
)
}
let
(
:from_date
)
{
10
.
days
.
ago
}
let
(
:from_date
)
{
10
.
days
.
ago
}
let
(
:user
)
{
create
(
:user
,
:admin
)
}
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
(
generate_cycle_analytics_spec
(
phase: :issue
,
phase: :issue
,
...
...
spec/models/cycle_analytics/plan_spec.rb
View file @
02e1e481
...
@@ -6,7 +6,7 @@ describe 'CycleAnalytics#plan', feature: true do
...
@@ -6,7 +6,7 @@ describe 'CycleAnalytics#plan', feature: true do
let
(
:project
)
{
create
(
:project
)
}
let
(
:project
)
{
create
(
:project
)
}
let
(
:from_date
)
{
10
.
days
.
ago
}
let
(
:from_date
)
{
10
.
days
.
ago
}
let
(
:user
)
{
create
(
:user
,
:admin
)
}
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
(
generate_cycle_analytics_spec
(
phase: :plan
,
phase: :plan
,
...
...
spec/models/cycle_analytics/production_spec.rb
View file @
02e1e481
...
@@ -6,7 +6,7 @@ describe 'CycleAnalytics#production', feature: true do
...
@@ -6,7 +6,7 @@ describe 'CycleAnalytics#production', feature: true do
let
(
:project
)
{
create
(
:project
)
}
let
(
:project
)
{
create
(
:project
)
}
let
(
:from_date
)
{
10
.
days
.
ago
}
let
(
:from_date
)
{
10
.
days
.
ago
}
let
(
:user
)
{
create
(
:user
,
:admin
)
}
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
(
generate_cycle_analytics_spec
(
phase: :production
,
phase: :production
,
...
...
spec/models/cycle_analytics/review_spec.rb
View file @
02e1e481
...
@@ -6,7 +6,7 @@ describe 'CycleAnalytics#review', feature: true do
...
@@ -6,7 +6,7 @@ describe 'CycleAnalytics#review', feature: true do
let
(
:project
)
{
create
(
:project
)
}
let
(
:project
)
{
create
(
:project
)
}
let
(
:from_date
)
{
10
.
days
.
ago
}
let
(
:from_date
)
{
10
.
days
.
ago
}
let
(
:user
)
{
create
(
:user
,
:admin
)
}
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
(
generate_cycle_analytics_spec
(
phase: :review
,
phase: :review
,
...
...
spec/models/cycle_analytics/staging_spec.rb
View file @
02e1e481
...
@@ -6,7 +6,7 @@ describe 'CycleAnalytics#staging', feature: true do
...
@@ -6,7 +6,7 @@ describe 'CycleAnalytics#staging', feature: true do
let
(
:project
)
{
create
(
:project
)
}
let
(
:project
)
{
create
(
:project
)
}
let
(
:from_date
)
{
10
.
days
.
ago
}
let
(
:from_date
)
{
10
.
days
.
ago
}
let
(
:user
)
{
create
(
:user
,
:admin
)
}
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
(
generate_cycle_analytics_spec
(
phase: :staging
,
phase: :staging
,
...
...
spec/models/cycle_analytics/summary_spec.rb
View file @
02e1e481
...
@@ -4,7 +4,7 @@ describe CycleAnalytics::Summary, models: true do
...
@@ -4,7 +4,7 @@ describe CycleAnalytics::Summary, models: true do
let
(
:project
)
{
create
(
:project
)
}
let
(
:project
)
{
create
(
:project
)
}
let
(
:from
)
{
Time
.
now
}
let
(
:from
)
{
Time
.
now
}
let
(
:user
)
{
create
(
:user
,
:admin
)
}
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
describe
"#new_issues"
do
it
"finds the number of issues created after the 'from date'"
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
...
@@ -6,7 +6,7 @@ describe 'CycleAnalytics#test', feature: true do
let
(
:project
)
{
create
(
:project
)
}
let
(
:project
)
{
create
(
:project
)
}
let
(
:from_date
)
{
10
.
days
.
ago
}
let
(
:from_date
)
{
10
.
days
.
ago
}
let
(
:user
)
{
create
(
:user
,
:admin
)
}
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
(
generate_cycle_analytics_spec
(
phase: :test
,
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
# rubocop:disable Metrics/AbcSize
# Note: The ABC size is large here because we have a method generating test cases with
# 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.
# multiple nested contexts. This shouldn't count as a violation.
module
CycleAnalyticsHelpers
module
CycleAnalyticsHelpers
module
TestGeneration
module
TestGeneration
# Generate the most common set of specs that all cycle analytics phases need to have.
# 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