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
72660d58
Commit
72660d58
authored
Oct 19, 2016
by
James Lopez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
plan events and spec working. Also added some TODOs to the code.
parent
3b5d9477
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
29 additions
and
14 deletions
+29
-14
lib/gitlab/cycle_analytics/events.rb
lib/gitlab/cycle_analytics/events.rb
+13
-2
lib/gitlab/cycle_analytics/events_fetcher.rb
lib/gitlab/cycle_analytics/events_fetcher.rb
+6
-2
lib/gitlab/cycle_analytics/metrics_fetcher.rb
lib/gitlab/cycle_analytics/metrics_fetcher.rb
+8
-8
spec/lib/gitlab/cycle_analytics/events_spec.rb
spec/lib/gitlab/cycle_analytics/events_spec.rb
+2
-2
No files found.
lib/gitlab/cycle_analytics/events.rb
View file @
72660d58
...
...
@@ -20,12 +20,23 @@ module Gitlab
end
def
plan_events
# TODO sort out 1st referenced commit and parse stuff
@fetcher
.
fetch_plan_events
@fetcher
.
fetch_plan_events
.
each
do
|
event
|
event
[
'total_time'
]
=
distance_of_time_in_words
(
event
[
'total_time'
].
to_f
)
commits
=
event
.
delete
(
'commits'
)
event
[
'commit'
]
=
first_time_reference_commit
(
commits
,
event
)
end
end
private
def
first_time_reference_commit
(
commits
,
event
)
st_commit
=
YAML
.
load
(
commits
).
detect
do
|
commit
|
commit
[
'created_at'
]
==
event
[
'first_mentioned_in_commit_at'
]
end
Commit
.
new
(
Gitlab
::
Git
::
Commit
.
new
(
st_commit
),
@project
)
end
def
interval_in_words
(
diff
)
"
#{
distance_of_time_in_words
(
diff
.
to_f
)
}
ago"
end
...
...
lib/gitlab/cycle_analytics/events_fetcher.rb
View file @
72660d58
...
...
@@ -23,8 +23,8 @@ module Gitlab
base_query
=
base_query_for
(
:plan
)
diff_fn
=
subtract_datetimes_diff
(
base_query
,
issue_table
[
:created_at
],
plan_attributes
)
query
=
base_query
.
join
(
m
erge_request_diff_table
).
on
(
merge_request_diff_table
[
:merge_request_id
].
eq
(
merge_request
_table
[
:id
])).
project
(
merge_request_diff_table
[
:st_commits
].
as
(
:commits
),
extract_epoch
(
diff_fn
).
as
(
'total_time'
)
).
query
=
base_query
.
join
(
m
r_diff_table
).
on
(
mr_diff_table
[
:merge_request_id
].
eq
(
mr
_table
[
:id
])).
project
(
extract_epoch
(
diff_fn
).
as
(
'total_time'
),
*
plan_projections
).
order
(
issue_table
[
:created_at
].
desc
)
ActiveRecord
::
Base
.
connection
.
execute
(
query
.
to_sql
).
to_a
...
...
@@ -45,6 +45,10 @@ module Gitlab
[
issue_table
[
:title
],
issue_table
[
:iid
],
issue_table
[
:created_at
],
User
.
arel_table
[
:name
]]
end
def
plan_projections
[
mr_diff_table
[
:st_commits
].
as
(
'commits'
),
issue_metrics_table
[
:first_mentioned_in_commit_at
]]
end
def
user_table
User
.
arel_table
end
...
...
lib/gitlab/cycle_analytics/metrics_fetcher.rb
View file @
72660d58
...
...
@@ -35,28 +35,28 @@ module Gitlab
where
(
issue_table
[
:created_at
].
gteq
(
@from
))
# Load merge_requests
query
=
query
.
join
(
m
erge_request
_table
,
Arel
::
Nodes
::
OuterJoin
).
on
(
m
erge_request
_table
[
:id
].
eq
(
mr_closing_issues_table
[
:merge_request_id
])).
join
(
m
erge_request
_metrics_table
).
on
(
m
erge_request_table
[
:id
].
eq
(
merge_request
_metrics_table
[
:merge_request_id
]))
query
=
query
.
join
(
m
r
_table
,
Arel
::
Nodes
::
OuterJoin
).
on
(
m
r
_table
[
:id
].
eq
(
mr_closing_issues_table
[
:merge_request_id
])).
join
(
m
r
_metrics_table
).
on
(
m
r_table
[
:id
].
eq
(
mr
_metrics_table
[
:merge_request_id
]))
if
DEPLOYMENT_METRIC_STAGES
.
include?
(
name
)
# Limit to merge requests that have been deployed to production after `@from`
query
.
where
(
m
erge_request
_metrics_table
[
:first_deployed_to_production_at
].
gteq
(
@from
))
query
.
where
(
m
r
_metrics_table
[
:first_deployed_to_production_at
].
gteq
(
@from
))
end
query
end
def
m
erge_request
_metrics_table
def
m
r
_metrics_table
MergeRequest
::
Metrics
.
arel_table
end
def
m
erge_request
_table
def
m
r
_table
MergeRequest
.
arel_table
end
def
m
erge_request
_diff_table
def
m
r
_diff_table
MergeRequestDiff
.
arel_table
end
...
...
spec/lib/gitlab/cycle_analytics/events_spec.rb
View file @
72660d58
...
...
@@ -38,8 +38,8 @@ describe Gitlab::CycleAnalytics::Events do
describe
'#plan_events'
do
let!
(
:context
)
{
create
(
:issue
,
project:
project
,
created_at:
2
.
days
.
ago
)
}
x
it
'has the first referenced commit'
do
expect
(
subject
.
plan_events
.
first
[
'commit'
]
).
to
eq
(
project
.
commit
)
it
'has the first referenced commit'
do
expect
(
subject
.
plan_events
.
first
[
'commit'
]
.
message
).
to
eq
(
'commit message'
)
end
it
'has the total time'
do
...
...
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