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
73e9ec63
Commit
73e9ec63
authored
Nov 15, 2016
by
James Lopez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
serialize all the things!
parent
8743e59f
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
34 additions
and
22 deletions
+34
-22
analytics_commit_entity.rb
app/serializers/analytics_commit_entity.rb
+14
-0
analytics_commit_serializer.rb
app/serializers/analytics_commit_serializer.rb
+3
-0
events.rb
lib/gitlab/cycle_analytics/events.rb
+11
-20
events_spec.rb
spec/lib/gitlab/cycle_analytics/events_spec.rb
+6
-2
No files found.
app/serializers/analytics_commit_entity.rb
0 → 100644
View file @
73e9ec63
class
AnalyticsCommitEntity
<
CommitEntity
include
RequestAwareEntity
include
EntityDateHelper
expose
:short_id
,
as: :short_sha
expose
:total_time
do
|
commit
|
distance_of_time_in_words
(
request
.
total_time
.
to_f
)
end
unexpose
:author_name
unexpose
:author_email
unexpose
:message
end
app/serializers/analytics_commit_serializer.rb
0 → 100644
View file @
73e9ec63
class
AnalyticsCommitSerializer
<
BaseSerializer
entity
AnalyticsCommitEntity
end
lib/gitlab/cycle_analytics/events.rb
View file @
73e9ec63
...
...
@@ -7,55 +7,46 @@ module Gitlab
end
def
issue_events
@fetcher
.
fetch
(
stage: :issue
).
map
{
|
event
|
pars
e_event
(
event
)
}
@fetcher
.
fetch
(
stage: :issue
).
map
{
|
event
|
serializ
e_event
(
event
)
}
end
def
plan_events
@fetcher
.
fetch
(
stage: :plan
).
each
do
|
event
|
event
[
'total_time'
]
=
distance_of_time_in_words
(
event
[
'total_time'
].
to_f
)
@fetcher
.
fetch
(
stage: :plan
).
map
do
|
event
|
commit
=
first_time_reference_commit
(
event
.
delete
(
'commits'
),
event
)
event
[
'title'
]
=
commit
.
title
event
[
'url'
]
=
Gitlab
::
LightUrlBuilder
.
build
(
entity: :commit
,
project:
@project
,
id:
commit
.
id
)
event
[
'sha'
]
=
commit
.
short_id
event
[
'author_name'
]
=
commit
.
author
.
name
event
[
'author_profile_url'
]
=
Gitlab
::
LightUrlBuilder
.
build
(
entity: :user
,
id:
commit
.
author
.
username
)
event
[
'author_avatar_url'
]
=
Gitlab
::
LightUrlBuilder
.
build
(
entity: :user_avatar
,
id:
commit
.
author
.
id
)
AnalyticsCommitSerializer
.
new
(
project:
@project
,
total_time:
event
[
'total_time'
]).
represent
(
commit
).
as_json
end
end
def
code_events
@fetcher
.
fetch
(
stage: :code
).
map
{
|
event
|
pars
e_event
(
event
,
entity: :merge_request
)
}
@fetcher
.
fetch
(
stage: :code
).
map
{
|
event
|
serializ
e_event
(
event
,
entity: :merge_request
)
}
end
def
test_events
@fetcher
.
fetch
(
stage: :test
).
map
do
|
event
|
parse_build_event
(
event
)
end
@fetcher
.
fetch
(
stage: :test
).
map
{
|
event
|
serialize_build_event
(
event
)
}
end
def
review_events
@fetcher
.
fetch
(
stage: :review
).
map
{
|
event
|
pars
e_event
(
event
,
entity: :merge_request
)
}
@fetcher
.
fetch
(
stage: :review
).
map
{
|
event
|
serializ
e_event
(
event
,
entity: :merge_request
)
}
end
def
staging_events
@fetcher
.
fetch
(
stage: :staging
).
map
do
|
event
|
parse_build_event
(
event
)
end
@fetcher
.
fetch
(
stage: :staging
).
map
{
|
event
|
serialize_build_event
(
event
)
}
end
def
production_events
@fetcher
.
fetch
(
stage: :production
).
map
{
|
event
|
pars
e_event
(
event
)
}
@fetcher
.
fetch
(
stage: :production
).
map
{
|
event
|
serializ
e_event
(
event
)
}
end
private
def
pars
e_event
(
event
,
entity: :issue
)
def
serializ
e_event
(
event
,
entity: :issue
)
event
[
'author'
]
=
User
.
find
(
event
.
delete
(
'author_id'
))
AnalyticsGenericSerializer
.
new
(
project:
@project
,
entity:
entity
).
represent
(
event
).
as_json
end
def
pars
e_build_event
(
event
)
def
serializ
e_build_event
(
event
)
build
=
::
Ci
::
Build
.
find
(
event
[
'id'
])
AnalyticsBuildSerializer
.
new
.
represent
(
build
).
as_json
...
...
spec/lib/gitlab/cycle_analytics/events_spec.rb
View file @
73e9ec63
...
...
@@ -52,7 +52,11 @@ describe Gitlab::CycleAnalytics::Events do
end
it
'has a sha short ID'
do
expect
(
subject
.
plan_events
.
first
[
:sha
]).
not_to
be_nil
expect
(
subject
.
plan_events
.
first
[
:short_sha
]).
not_to
be_nil
end
it
'has the URL'
do
expect
(
subject
.
plan_events
.
first
[
:commit_url
]).
not_to
be_nil
end
it
'has the total time'
do
...
...
@@ -68,7 +72,7 @@ describe Gitlab::CycleAnalytics::Events do
end
it
"has the author's name"
do
expect
(
subject
.
plan_events
.
first
[
:author
][
:name
]).
to
eq
(
context
.
author
.
name
)
expect
(
subject
.
plan_events
.
first
[
:author
][
:name
]).
not_to
be_nil
end
end
...
...
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