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
6a2737e6
Commit
6a2737e6
authored
Nov 15, 2016
by
James Lopez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
WIP - refactor events to use a generic build entity for some of the hybrid events
parent
0ddf825d
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
28 additions
and
44 deletions
+28
-44
analytics_generic_entity.rb
app/serializers/analytics_generic_entity.rb
+1
-1
events.rb
lib/gitlab/cycle_analytics/events.rb
+4
-10
events_fetcher.rb
lib/gitlab/cycle_analytics/events_fetcher.rb
+0
-10
query_config.rb
lib/gitlab/cycle_analytics/query_config.rb
+4
-12
analytics_build_entity_spec.rb
spec/serializers/analytics_build_entity_spec.rb
+3
-3
analytics_build_serializer_spec.rb
spec/serializers/analytics_build_serializer_spec.rb
+2
-4
analytics_generic_serializer_spec.rb
spec/serializers/analytics_generic_serializer_spec.rb
+14
-4
No files found.
app/serializers/analytics_generic_entity.rb
View file @
6a2737e6
...
...
@@ -23,7 +23,7 @@ class AnalyticsGenericEntity < Grape::Entity
private
def
url_to
(
route
,
id
=
nil
)
public_send
(
"
#{
route
}
_url"
,
options
[
:project
].
namespace
,
options
[
:project
]
,
id
)
public_send
(
"
#{
route
}
_url"
,
request
.
project
.
namespace
,
request
.
project
,
id
)
end
def
interval_in_words
(
diff
)
...
...
lib/gitlab/cycle_analytics/events.rb
View file @
6a2737e6
module
Gitlab
module
CycleAnalytics
class
Events
include
ActionView
::
Helpers
::
DateHelper
def
initialize
(
project
:,
options
:)
@project
=
project
@fetcher
=
EventsFetcher
.
new
(
project:
project
,
options:
options
)
...
...
@@ -51,20 +49,16 @@ module Gitlab
private
def
parse_event
(
event
,
entity: :issue
)
event
[
'url'
]
=
Gitlab
::
LightUrlBuilder
.
build
(
entity:
entity
,
project:
@project
,
id:
event
[
'iid'
].
to_s
)
event
[
'total_time'
]
=
distance_of_time_in_words
(
event
[
'total_time'
].
to_f
)
event
[
'created_at'
]
=
interval_in_words
(
event
[
'created_at'
])
event
[
'author_profile_url'
]
=
Gitlab
::
LightUrlBuilder
.
build
(
entity: :user
,
id:
event
[
'author_username'
])
event
[
'author_avatar_url'
]
=
Gitlab
::
LightUrlBuilder
.
build
(
entity: :user_avatar
,
id:
event
[
'author_id'
])
def
parse_event
(
event
)
event
[
'author'
]
=
User
.
find
(
event
.
remove
(
'author_id'
))
event
.
except!
(
'author_id'
,
'author_username'
)
AnalyticsGenericSerializer
.
new
(
project:
@project
).
represent
(
event
).
as_json
end
def
parse_build_event
(
event
)
build
=
::
Ci
::
Build
.
find
(
event
[
'id'
])
AnalyticsBuildSerializer
.
new
(
project:
@project
)
.
represent
(
build
).
as_json
AnalyticsBuildSerializer
.
new
.
represent
(
build
).
as_json
end
def
first_time_reference_commit
(
commits
,
event
)
...
...
lib/gitlab/cycle_analytics/events_fetcher.rb
View file @
6a2737e6
...
...
@@ -15,24 +15,14 @@ module Gitlab
end
end
def
issue_custom_query
(
base_query
)
base_query
.
join
(
user_table
).
on
(
issue_table
[
:author_id
].
eq
(
user_table
[
:id
]))
end
def
plan_custom_query
(
base_query
)
base_query
.
join
(
mr_diff_table
).
on
(
mr_diff_table
[
:merge_request_id
].
eq
(
mr_table
[
:id
]))
end
def
review_custom_query
(
base_query
)
base_query
.
join
(
user_table
).
on
(
mr_table
[
:author_id
].
eq
(
user_table
[
:id
]))
end
def
test_custom_query
(
base_query
)
base_query
.
join
(
build_table
).
on
(
mr_metrics_table
[
:ci_commit_id
].
eq
(
build_table
[
:commit_id
]))
end
alias_method
:code_custom_query
,
:issue_custom_query
alias_method
:production_custom_query
,
:issue_custom_query
alias_method
:staging_custom_query
,
:test_custom_query
end
end
...
...
lib/gitlab/cycle_analytics/query_config.rb
View file @
6a2737e6
...
...
@@ -24,9 +24,7 @@ module Gitlab
issue_table
[
:iid
],
issue_table
[
:id
],
issue_table
[
:created_at
],
user_table
[
:name
].
as
(
'author_name'
),
user_table
[
:username
].
as
(
'author_username'
),
user_table
[
:id
].
as
(
'author_id'
)]
issue_table
[
:author_id
]]
}
end
...
...
@@ -48,9 +46,7 @@ module Gitlab
mr_table
[
:id
],
mr_table
[
:created_at
],
mr_table
[
:state
],
user_table
[
:name
].
as
(
'author_name'
),
user_table
[
:username
].
as
(
'author_username'
),
user_table
[
:id
].
as
(
'author_id'
)],
mr_table
[
:author_id
]],
order:
mr_table
[
:created_at
]
}
end
...
...
@@ -73,9 +69,7 @@ module Gitlab
mr_table
[
:id
],
mr_table
[
:created_at
].
as
(
'opened_at'
),
mr_table
[
:state
],
user_table
[
:name
].
as
(
'author_name'
),
user_table
[
:username
].
as
(
'author_username'
),
user_table
[
:id
].
as
(
'author_id'
)]
mr_table
[
:author_id
]]
}
end
...
...
@@ -96,9 +90,7 @@ module Gitlab
issue_table
[
:iid
],
issue_table
[
:id
],
issue_table
[
:created_at
],
user_table
[
:name
].
as
(
'author_name'
),
user_table
[
:username
].
as
(
'author_username'
),
user_table
[
:id
].
as
(
'author_id'
)]
issue_table
[
:author_id
]]
}
end
end
...
...
spec/serializers/analytics_build_entity_spec.rb
View file @
6a2737e6
...
...
@@ -5,14 +5,14 @@ describe AnalyticsBuildEntity do
described_class
.
new
(
build
,
request:
double
)
end
context
'
when build is a regular job
'
do
context
'
build with an author
'
do
let
(
:user
)
{
create
(
:user
)
}
let
(
:build
)
{
create
(
:ci_build
,
author:
user
)
}
subject
{
entity
.
as_json
}
it
'contains
URLs
'
do
expect
(
subject
).
to
include
(
:url
,
:branch_url
,
:commit_url
)
it
'contains
the URL
'
do
expect
(
subject
).
to
include
(
:url
)
end
it
'contains the author'
do
...
...
spec/serializers/analytics_build_serializer_spec.rb
View file @
6a2737e6
...
...
@@ -3,12 +3,10 @@ require 'spec_helper'
describe
AnalyticsBuildSerializer
do
let
(
:serializer
)
do
described_class
.
new
(
project:
project
)
.
represent
(
resource
)
.
new
.
represent
(
resource
)
end
let
(
:json
)
{
serializer
.
as_json
}
let
(
:project
)
{
create
(
:project
)
}
let
(
:resource
)
{
create
(
:ci_build
)
}
context
'when there is a single object provided'
do
...
...
@@ -18,7 +16,7 @@ describe AnalyticsBuildSerializer do
it
'contains important elements of analyticsBuild'
do
expect
(
json
)
.
to
include
(
:name
,
:branch
,
:short_sha
,
:date
,
:total_time
,
:url
,
:
branch_url
,
:commit_url
,
:
author
)
.
to
include
(
:name
,
:branch
,
:short_sha
,
:date
,
:total_time
,
:url
,
:author
)
end
end
end
spec/serializers/analytics_generic_serializer_spec.rb
View file @
6a2737e6
require
'spec_helper'
describe
Analytics
Build
Serializer
do
describe
Analytics
Generic
Serializer
do
let
(
:serializer
)
do
described_class
.
new
(
project:
project
)
.
represent
(
resource
)
end
let
(
:user
)
{
create
(
:user
)
}
let
(
:json
)
{
serializer
.
as_json
}
let
(
:project
)
{
create
(
:project
)
}
let
(
:resource
)
{
create
(
:ci_build
)
}
let
(
:resource
)
{
{
total_time:
"172802.724419"
,
title:
"Eos voluptatem inventore in sed."
,
iid:
"1"
,
id:
"1"
,
created_at:
"2016-11-12 15:04:02.948604"
,
author:
user
,
entity: :merge_request
}
}
context
'when there is a single object provided'
do
it
'it generates payload for single object'
do
...
...
@@ -17,8 +28,7 @@ describe AnalyticsBuildSerializer do
end
it
'contains important elements of analyticsBuild'
do
expect
(
json
)
.
to
include
(
:name
,
:branch
,
:short_sha
,
:date
,
:total_time
,
:url
,
:branch_url
,
:commit_url
,
:author
)
expect
(
json
).
to
include
(
:title
,
:iid
,
:date
,
:total_time
,
:url
,
:author
)
end
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