BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
cbd7d000
Commit
cbd7d000
authored
Nov 16, 2016
by
James Lopez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added custom date helper and spec and fixed some unrelated spec failures
parent
4844476e
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
94 additions
and
27 deletions
+94
-27
analytics_build_entity.rb
app/serializers/analytics_build_entity.rb
+1
-1
analytics_commit_entity.rb
app/serializers/analytics_commit_entity.rb
+1
-1
analytics_generic_entity.rb
app/serializers/analytics_generic_entity.rb
+5
-2
entity_date_helper.rb
app/serializers/entity_date_helper.rb
+28
-0
events_spec.rb
spec/lib/gitlab/cycle_analytics/events_spec.rb
+7
-7
cycle_analytics_events_spec.rb
spec/requests/projects/cycle_analytics_events_spec.rb
+6
-16
entity_date_helper_spec.rb
spec/serializers/entity_date_helper_spec.rb
+46
-0
No files found.
app/serializers/analytics_build_entity.rb
View file @
cbd7d000
...
...
@@ -13,7 +13,7 @@ class AnalyticsBuildEntity < Grape::Entity
end
expose
:duration
,
as: :total_time
do
|
build
|
distance_of_time_
in_words
(
build
[
:duration
].
to_f
)
distance_of_time_
as_hash
(
build
[
:duration
].
to_f
)
end
expose
:branch
do
...
...
app/serializers/analytics_commit_entity.rb
View file @
cbd7d000
...
...
@@ -5,7 +5,7 @@ class AnalyticsCommitEntity < CommitEntity
expose
:short_id
,
as: :short_sha
expose
:total_time
do
|
commit
|
distance_of_time_
in_words
(
request
.
total_time
.
to_f
)
distance_of_time_
as_hash
(
request
.
total_time
.
to_f
)
end
unexpose
:author_name
...
...
app/serializers/analytics_generic_entity.rb
View file @
cbd7d000
...
...
@@ -3,12 +3,15 @@ class AnalyticsGenericEntity < Grape::Entity
include
EntityDateHelper
expose
:title
expose
:iid
expose
:state
,
if:
->
(
_instance
,
options
)
{
options
[
:request
].
entity
==
:merge_request
}
expose
:author
,
using:
UserEntity
expose
:iid
do
|
object
|
object
[
:iid
].
to_s
end
expose
:total_time
do
|
object
|
distance_of_time_
in_words
(
object
[
:total_time
].
to_f
)
distance_of_time_
as_hash
(
object
[
:total_time
].
to_f
)
end
expose
(
:created_at
)
do
|
object
|
...
...
app/serializers/entity_date_helper.rb
View file @
cbd7d000
...
...
@@ -4,4 +4,32 @@ module EntityDateHelper
def
interval_in_words
(
diff
)
"
#{
distance_of_time_in_words
(
diff
.
to_f
)
}
ago"
end
# Converts seconds into a hash such as:
# { days: 1, hours: 3, mins: 42, seconds: 40 }
#
# It returns 0 seconds for zero or negative numbers
# It rounds to nearest time unit and does not return zero
# i.e { min: 1 } instead of { mins: 1, seconds: 0 }
def
distance_of_time_as_hash
(
diff
)
diff
=
diff
.
abs
.
floor
return
{
seconds:
0
}
if
diff
==
0
mins
=
(
diff
/
60
).
floor
seconds
=
diff
%
60
hours
=
(
mins
/
60
).
floor
mins
=
mins
%
60
days
=
(
hours
/
24
).
floor
hours
=
hours
%
24
duration_hash
=
{}
duration_hash
[
:days
]
=
days
if
days
>
0
duration_hash
[
:hours
]
=
hours
if
hours
>
0
duration_hash
[
:mins
]
=
mins
if
mins
>
0
duration_hash
[
:seconds
]
=
seconds
if
seconds
>
0
duration_hash
end
end
spec/lib/gitlab/cycle_analytics/events_spec.rb
View file @
cbd7d000
...
...
@@ -16,7 +16,7 @@ describe Gitlab::CycleAnalytics::Events do
describe
'#issue_events'
do
it
'has the total time'
do
expect
(
subject
.
issue_events
.
first
[
:total_time
]).
to
eq
(
'2 days'
)
expect
(
subject
.
issue_events
.
first
[
:total_time
]).
not_to
be_empty
end
it
'has a title'
do
...
...
@@ -62,7 +62,7 @@ describe Gitlab::CycleAnalytics::Events do
end
it
'has the total time'
do
expect
(
subject
.
plan_events
.
first
[
:total_time
]).
to
eq
(
'less than a minute'
)
expect
(
subject
.
plan_events
.
first
[
:total_time
]).
not_to
be_empty
end
it
"has the author's URL"
do
...
...
@@ -84,7 +84,7 @@ describe Gitlab::CycleAnalytics::Events do
end
it
'has the total time'
do
expect
(
subject
.
code_events
.
first
[
:total_time
]).
to
eq
(
'less than a minute'
)
expect
(
subject
.
code_events
.
first
[
:total_time
]).
not_to
be_empty
end
it
'has a title'
do
...
...
@@ -162,7 +162,7 @@ describe Gitlab::CycleAnalytics::Events do
end
it
'has the total time'
do
expect
(
subject
.
test_events
.
first
[
:total_time
]).
not_to
be_
nil
expect
(
subject
.
test_events
.
first
[
:total_time
]).
not_to
be_
empty
end
end
...
...
@@ -170,7 +170,7 @@ describe Gitlab::CycleAnalytics::Events do
let!
(
:context
)
{
create
(
:issue
,
project:
project
,
created_at:
2
.
days
.
ago
)
}
it
'has the total time'
do
expect
(
subject
.
review_events
.
first
[
:total_time
]).
to
eq
(
'less than a minute'
)
expect
(
subject
.
review_events
.
first
[
:total_time
]).
not_to
be_empty
end
it
'has a title'
do
...
...
@@ -259,7 +259,7 @@ describe Gitlab::CycleAnalytics::Events do
end
it
'has the total time'
do
expect
(
subject
.
staging_events
.
first
[
:total_time
]).
not_to
be_
nil
expect
(
subject
.
staging_events
.
first
[
:total_time
]).
not_to
be_
empty
end
it
"has the author's URL"
do
...
...
@@ -284,7 +284,7 @@ describe Gitlab::CycleAnalytics::Events do
end
it
'has the total time'
do
expect
(
subject
.
production_events
.
first
[
:total_time
]).
to
eq
(
'2 days'
)
expect
(
subject
.
production_events
.
first
[
:total_time
]).
not_to
be_empty
end
it
'has a title'
do
...
...
spec/requests/projects/cycle_analytics_events_spec.rb
View file @
cbd7d000
...
...
@@ -3,17 +3,18 @@ require 'spec_helper'
describe
'cycle analytics events'
do
let
(
:user
)
{
create
(
:user
)
}
let
(
:project
)
{
create
(
:project
)
}
let
(
:issue
)
{
create
(
:issue
,
project:
project
,
created_at:
2
.
days
.
ago
)
}
describe
'GET /:namespace/:project/cycle_analytics/events/issues'
do
before
do
project
.
team
<<
[
user
,
:developer
]
allow_any_instance_of
(
Gitlab
::
ReferenceExtractor
).
to
receive
(
:issues
).
and_return
([
issue
])
3
.
times
{
create_cycle
}
deploy_master
login_as
(
user
)
allow_any_instance_of
(
Gitlab
::
ReferenceExtractor
).
to
receive
(
:issues
).
and_return
([
context
])
end
it
'lists the issue events'
do
...
...
@@ -31,17 +32,7 @@ describe 'cycle analytics events' do
expect
(
json_response
[
'events'
]).
not_to
be_empty
commits
=
[]
MergeRequest
.
all
.
each
do
|
mr
|
mr
.
merge_request_diff
.
st_commits
.
each
do
|
commit
|
commits
<<
{
date:
commit
[
:authored_date
],
sha:
commit
[
:id
]
}
end
end
newest_sha
=
commits
.
sort_by
{
|
k
|
k
[
'date'
]
}.
first
[
:sha
][
0
...
8
]
expect
(
json_response
[
'events'
].
first
[
'short_sha'
]).
to
eq
(
newest_sha
)
expect
(
json_response
[
'events'
].
first
[
'short_sha'
]).
to
eq
(
MergeRequest
.
last
.
commits
.
first
.
short_id
)
end
it
'lists the code events'
do
...
...
@@ -49,7 +40,7 @@ describe 'cycle analytics events' do
expect
(
json_response
[
'events'
]).
not_to
be_empty
first_mr_iid
=
Issue
.
order
(
created_at: :desc
).
pluck
(
:iid
).
first
.
to_s
first_mr_iid
=
MergeRequest
.
order
(
created_at: :desc
).
pluck
(
:iid
).
first
.
to_s
expect
(
json_response
[
'events'
].
first
[
'iid'
]).
to
eq
(
first_mr_iid
)
end
...
...
@@ -67,7 +58,7 @@ describe 'cycle analytics events' do
expect
(
json_response
[
'events'
]).
not_to
be_empty
first_mr_iid
=
Issue
.
order
(
created_at: :desc
).
pluck
(
:iid
).
first
.
to_s
first_mr_iid
=
MergeRequest
.
order
(
created_at: :desc
).
pluck
(
:iid
).
first
.
to_s
expect
(
json_response
[
'events'
].
first
[
'iid'
]).
to
eq
(
first_mr_iid
)
end
...
...
@@ -132,7 +123,6 @@ describe 'cycle analytics events' do
end
def
create_cycle
issue
=
create
(
:issue
,
project:
project
,
created_at:
2
.
days
.
ago
)
milestone
=
create
(
:milestone
,
project:
project
)
issue
.
update
(
milestone:
milestone
)
mr
=
create_merge_request_closing_issue
(
issue
)
...
...
spec/serializers/entity_date_helper_spec.rb
0 → 100644
View file @
cbd7d000
require
'spec_helper'
describe
EntityDateHelper
do
let
(
:date_helper_class
)
{
Class
.
new
{
include
EntityDateHelper
}.
new
}
it
'converts 0 seconds'
do
expect
(
date_helper_class
.
distance_of_time_as_hash
(
0
)).
to
eq
(
seconds:
0
)
end
it
'converts 40 seconds'
do
expect
(
date_helper_class
.
distance_of_time_as_hash
(
40
)).
to
eq
(
seconds:
40
)
end
it
'converts 60 seconds'
do
expect
(
date_helper_class
.
distance_of_time_as_hash
(
60
)).
to
eq
(
mins:
1
)
end
it
'converts 70 seconds'
do
expect
(
date_helper_class
.
distance_of_time_as_hash
(
70
)).
to
eq
(
mins:
1
,
seconds:
10
)
end
it
'converts 3600 seconds'
do
expect
(
date_helper_class
.
distance_of_time_as_hash
(
3600
)).
to
eq
(
hours:
1
)
end
it
'converts 3750 seconds'
do
expect
(
date_helper_class
.
distance_of_time_as_hash
(
3750
)).
to
eq
(
hours:
1
,
mins:
2
,
seconds:
30
)
end
it
'converts 86400 seconds'
do
expect
(
date_helper_class
.
distance_of_time_as_hash
(
86400
)).
to
eq
(
days:
1
)
end
it
'converts 86560 seconds'
do
expect
(
date_helper_class
.
distance_of_time_as_hash
(
86560
)).
to
eq
(
days:
1
,
mins:
2
,
seconds:
40
)
end
it
'converts 86760 seconds'
do
expect
(
date_helper_class
.
distance_of_time_as_hash
(
99760
)).
to
eq
(
days:
1
,
hours:
3
,
mins:
42
,
seconds:
40
)
end
it
'converts 986760 seconds'
do
expect
(
date_helper_class
.
distance_of_time_as_hash
(
986760
)).
to
eq
(
days:
11
,
hours:
10
,
mins:
6
)
end
end
\ No newline at end of file
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