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
Boxiang Sun
gitlab-ce
Commits
df6c9c33
Commit
df6c9c33
authored
Aug 26, 2016
by
Timothy Andrew
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Scope Cycle Analytics queries to a project
parent
a81de9ab
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
29 additions
and
20 deletions
+29
-20
app/controllers/projects/cycle_analytics_controller.rb
app/controllers/projects/cycle_analytics_controller.rb
+1
-1
app/models/cycle_analytics.rb
app/models/cycle_analytics.rb
+11
-7
app/models/cycle_analytics/queries.rb
app/models/cycle_analytics/queries.rb
+4
-4
spec/models/cycle_analytics/issue_spec.rb
spec/models/cycle_analytics/issue_spec.rb
+13
-8
No files found.
app/controllers/projects/cycle_analytics_controller.rb
View file @
df6c9c33
class
Projects::CycleAnalyticsController
<
Projects
::
ApplicationController
class
Projects::CycleAnalyticsController
<
Projects
::
ApplicationController
def
show
def
show
@cycle_analytics
=
CycleAnalytics
.
new
@cycle_analytics
=
CycleAnalytics
.
new
(
@project
)
end
end
end
end
app/models/cycle_analytics.rb
View file @
df6c9c33
class
CycleAnalytics
class
CycleAnalytics
def
initialize
(
project
)
@project
=
project
end
def
issue
def
issue
calculate_metric
(
Queries
::
issues
,
calculate_metric
(
Queries
::
issues
(
@project
)
,
->
(
data_point
)
{
data_point
[
:issue
].
created_at
},
->
(
data_point
)
{
data_point
[
:issue
].
created_at
},
[
Queries
::
issue_first_associated_with_milestone_at
,
Queries
::
issue_first_added_to_list_label_at
])
[
Queries
::
issue_first_associated_with_milestone_at
,
Queries
::
issue_first_added_to_list_label_at
])
end
end
def
plan
def
plan
calculate_metric
(
Queries
::
issues
,
calculate_metric
(
Queries
::
issues
(
@project
)
,
[
Queries
::
issue_first_associated_with_milestone_at
,
Queries
::
issue_first_added_to_list_label_at
],
[
Queries
::
issue_first_associated_with_milestone_at
,
Queries
::
issue_first_added_to_list_label_at
],
Queries
::
issue_closing_merge_request_opened_at
)
Queries
::
issue_closing_merge_request_opened_at
)
end
end
def
code
def
code
calculate_metric
(
Queries
::
merge_requests_closing_issues
,
calculate_metric
(
Queries
::
merge_requests_closing_issues
(
@project
)
,
->
(
data_point
)
{
data_point
[
:merge_request
].
created_at
},
->
(
data_point
)
{
data_point
[
:merge_request
].
created_at
},
[
Queries
::
merge_request_first_assigned_to_user_other_than_author_at
,
Queries
::
merge_request_wip_flag_first_removed_at
])
[
Queries
::
merge_request_first_assigned_to_user_other_than_author_at
,
Queries
::
merge_request_wip_flag_first_removed_at
])
end
end
def
test
def
test
calculate_metric
(
Queries
::
merge_requests_closing_issues
,
calculate_metric
(
Queries
::
merge_requests_closing_issues
(
@project
)
,
Queries
::
merge_request_build_started_at
,
Queries
::
merge_request_build_started_at
,
Queries
::
merge_request_build_finished_at
)
Queries
::
merge_request_build_finished_at
)
end
end
def
review
def
review
calculate_metric
(
Queries
::
merge_requests_closing_issues
,
calculate_metric
(
Queries
::
merge_requests_closing_issues
(
@project
)
,
[
Queries
::
merge_request_first_assigned_to_user_other_than_author_at
,
Queries
::
merge_request_wip_flag_first_removed_at
],
[
Queries
::
merge_request_first_assigned_to_user_other_than_author_at
,
Queries
::
merge_request_wip_flag_first_removed_at
],
[
Queries
::
merge_request_first_closed_at
,
Queries
::
merge_request_merged_at
])
[
Queries
::
merge_request_first_closed_at
,
Queries
::
merge_request_merged_at
])
end
end
def
staging
def
staging
calculate_metric
(
Queries
::
merge_requests_closing_issues
,
calculate_metric
(
Queries
::
merge_requests_closing_issues
(
@project
)
,
Queries
::
merge_request_merged_at
,
Queries
::
merge_request_merged_at
,
Queries
::
merge_request_deployed_to_any_environment_at
)
Queries
::
merge_request_deployed_to_any_environment_at
)
end
end
def
production
def
production
calculate_metric
(
Queries
::
merge_requests_closing_issues
,
calculate_metric
(
Queries
::
merge_requests_closing_issues
(
@project
)
,
->
(
data_point
)
{
data_point
[
:issue
].
created_at
},
->
(
data_point
)
{
data_point
[
:issue
].
created_at
},
Queries
::
merge_request_deployed_to_production_at
)
Queries
::
merge_request_deployed_to_production_at
)
end
end
...
...
app/models/cycle_analytics/queries.rb
View file @
df6c9c33
class
CycleAnalytics
class
CycleAnalytics
module
Queries
module
Queries
class
<<
self
class
<<
self
def
issues
def
issues
(
project
)
Issue
.
all
.
to_a
.
map
{
|
issue
|
{
issue:
issue
}
}
project
.
issues
.
map
{
|
issue
|
{
issue:
issue
}
}
end
end
def
merge_requests_closing_issues
def
merge_requests_closing_issues
(
project
)
issues
.
map
do
|
data_point
|
issues
(
project
)
.
map
do
|
data_point
|
merge_requests
=
data_point
[
:issue
].
closed_by_merge_requests
(
nil
,
check_if_open:
false
)
merge_requests
=
data_point
[
:issue
].
closed_by_merge_requests
(
nil
,
check_if_open:
false
)
merge_requests
.
map
{
|
merge_request
|
{
issue:
data_point
[
:issue
],
merge_request:
merge_request
}
}
merge_requests
.
map
{
|
merge_request
|
{
issue:
data_point
[
:issue
],
merge_request:
merge_request
}
}
end
.
flatten
end
.
flatten
...
...
spec/models/cycle_analytics/issue_spec.rb
View file @
df6c9c33
...
@@ -2,7 +2,7 @@ require 'spec_helper'
...
@@ -2,7 +2,7 @@ require 'spec_helper'
describe
'CycleAnalytics#issue'
,
models:
true
do
describe
'CycleAnalytics#issue'
,
models:
true
do
let
(
:project
)
{
create
(
:project
)
}
let
(
:project
)
{
create
(
:project
)
}
subject
{
CycleAnalytics
.
new
}
subject
{
CycleAnalytics
.
new
(
project
)
}
context
"when calculating the median of times between:
context
"when calculating the median of times between:
start: issue created_at
start: issue created_at
...
@@ -26,6 +26,16 @@ describe 'CycleAnalytics#issue', models: true do
...
@@ -26,6 +26,16 @@ describe 'CycleAnalytics#issue', models: true do
median_start_time
,
median_end_time
=
start_and_end_times
[
2
]
median_start_time
,
median_end_time
=
start_and_end_times
[
2
]
expect
(
subject
.
issue
).
to
eq
(
median_end_time
-
median_start_time
)
expect
(
subject
.
issue
).
to
eq
(
median_end_time
-
median_start_time
)
end
end
it
"does not include issues from other projects"
do
5
.
times
do
milestone
=
create
(
:milestone
,
project:
project
)
issue
=
create
(
:issue
)
issue
.
update
(
milestone:
milestone
)
end
expect
(
subject
.
issue
).
to
be_nil
end
end
end
context
"when a label is added to the issue"
do
context
"when a label is added to the issue"
do
...
@@ -47,14 +57,9 @@ describe 'CycleAnalytics#issue', models: true do
...
@@ -47,14 +57,9 @@ describe 'CycleAnalytics#issue', models: true do
it
"does not make a calculation for regular labels"
do
it
"does not make a calculation for regular labels"
do
5
.
times
do
5
.
times
do
start_time
=
Time
.
now
end_time
=
rand
(
1
..
10
).
days
.
from_now
regular_label
=
create
(
:label
)
regular_label
=
create
(
:label
)
issue
=
Timecop
.
freeze
(
start_time
)
{
create
(
:issue
,
project:
project
)
}
issue
=
create
(
:issue
,
project:
project
)
Timecop
.
freeze
(
end_time
)
{
issue
.
update
(
label_ids:
[
regular_label
.
id
])
}
issue
.
update
(
label_ids:
[
regular_label
.
id
])
[
start_time
,
end_time
]
end
end
expect
(
subject
.
issue
).
to
be_nil
expect
(
subject
.
issue
).
to
be_nil
...
...
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