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
Léo-Paul Géneau
gitlab-ce
Commits
3b5d9477
Commit
3b5d9477
authored
Oct 19, 2016
by
James Lopez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
commit events and spec
parent
1d6068a1
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
53 additions
and
10 deletions
+53
-10
lib/gitlab/cycle_analytics/events.rb
lib/gitlab/cycle_analytics/events.rb
+13
-3
lib/gitlab/cycle_analytics/events_fetcher.rb
lib/gitlab/cycle_analytics/events_fetcher.rb
+21
-4
lib/gitlab/cycle_analytics/metrics_fetcher.rb
lib/gitlab/cycle_analytics/metrics_fetcher.rb
+4
-0
spec/lib/gitlab/cycle_analytics/events_spec.rb
spec/lib/gitlab/cycle_analytics/events_spec.rb
+15
-3
No files found.
lib/gitlab/cycle_analytics/events.rb
View file @
3b5d9477
...
...
@@ -9,15 +9,25 @@ module Gitlab
@fetcher
=
EventsFetcher
.
new
(
project:
project
,
from:
from
)
end
#TODO: backend pagination - specially for commits, etc...
def
issue_events
@fetcher
.
fetch_issues
.
each
do
|
event
|
event
[
'issue_diff'
]
=
interval_in_words
(
event
[
'issue_diff'
])
#TODO figure out what the frontend needs for displaying the avatar
@fetcher
.
fetch_issue_events
.
each
do
|
event
|
event
[
'total_time'
]
=
distance_of_time_in_words
(
event
[
'total_time'
].
to_f
)
event
[
'created_at'
]
=
interval_in_words
(
event
[
'created_at'
])
end
end
def
plan_events
# TODO sort out 1st referenced commit and parse stuff
@fetcher
.
fetch_plan_events
end
private
def
interval_in_words
(
diff
)
"
#{
distance_of_time_in_words
(
diff
.
to_f
)
}
ago"
"
#{
distance_of_time_in_words
(
diff
.
to_f
)
}
ago"
end
end
end
...
...
lib/gitlab/cycle_analytics/events_fetcher.rb
View file @
3b5d9477
...
...
@@ -8,22 +8,39 @@ module Gitlab
@from
=
from
end
def
fetch_issues
def
fetch_issue
_event
s
base_query
=
base_query_for
(
:issue
)
diff_fn
=
subtract_datetimes_diff
(
base_query
,
issue_table
[
:created_at
],
metric
_attributes
)
diff_fn
=
subtract_datetimes_diff
(
base_query
,
issue_table
[
:created_at
],
issue
_attributes
)
query
=
base_query
.
join
(
user_table
).
on
(
issue_table
[
:author_id
].
eq
(
user_table
[
:id
])).
project
(
extract_epoch
(
diff_fn
).
as
(
'
issue_diff
'
),
*
issue_projections
).
project
(
extract_epoch
(
diff_fn
).
as
(
'
total_time
'
),
*
issue_projections
).
order
(
issue_table
[
:created_at
].
desc
)
ActiveRecord
::
Base
.
connection
.
execute
(
query
.
to_sql
).
to_a
end
def
metric_attributes
def
fetch_plan_events
base_query
=
base_query_for
(
:plan
)
diff_fn
=
subtract_datetimes_diff
(
base_query
,
issue_table
[
:created_at
],
plan_attributes
)
query
=
base_query
.
join
(
merge_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'
)).
order
(
issue_table
[
:created_at
].
desc
)
ActiveRecord
::
Base
.
connection
.
execute
(
query
.
to_sql
).
to_a
end
private
def
issue_attributes
[
issue_metrics_table
[
:first_associated_with_milestone_at
],
issue_metrics_table
[
:first_added_to_board_at
]]
end
def
plan_attributes
issue_attributes
+
[
issue_metrics_table
[
:first_mentioned_in_commit_at
]]
end
def
issue_projections
[
issue_table
[
:title
],
issue_table
[
:iid
],
issue_table
[
:created_at
],
User
.
arel_table
[
:name
]]
end
...
...
lib/gitlab/cycle_analytics/metrics_fetcher.rb
View file @
3b5d9477
...
...
@@ -56,6 +56,10 @@ module Gitlab
MergeRequest
.
arel_table
end
def
merge_request_diff_table
MergeRequestDiff
.
arel_table
end
def
mr_closing_issues_table
MergeRequestsClosingIssues
.
arel_table
end
...
...
spec/lib/gitlab/cycle_analytics/events_spec.rb
View file @
3b5d9477
...
...
@@ -11,11 +11,11 @@ describe Gitlab::CycleAnalytics::Events do
setup
(
context
)
end
describe
'#issue'
do
describe
'#issue
_events
'
do
let!
(
:context
)
{
create
(
:issue
,
project:
project
,
created_at:
2
.
days
.
ago
)
}
it
'has
an issue diff
'
do
expect
(
subject
.
issue_events
.
first
[
'
issue_diff'
]).
to
eq
(
'2 days ago
'
)
it
'has
the total time
'
do
expect
(
subject
.
issue_events
.
first
[
'
total_time'
]).
to
eq
(
'2 days
'
)
end
it
'has a title'
do
...
...
@@ -35,6 +35,18 @@ describe Gitlab::CycleAnalytics::Events do
end
end
describe
'#plan_events'
do
let!
(
:context
)
{
create
(
:issue
,
project:
project
,
created_at:
2
.
days
.
ago
)
}
xit
'has the first referenced commit'
do
expect
(
subject
.
plan_events
.
first
[
'commit'
]).
to
eq
(
project
.
commit
)
end
it
'has the total time'
do
expect
(
subject
.
plan_events
.
first
[
'total_time'
]).
to
eq
(
'2 days'
)
end
end
def
setup
(
context
)
milestone
=
create
(
:milestone
,
project:
project
)
context
.
update
(
milestone:
milestone
)
...
...
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