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
81d0146c
Commit
81d0146c
authored
Nov 14, 2016
by
James Lopez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
WIP - refactoring URL builder and events presenter into serializers
parent
1744d633
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
81 additions
and
12 deletions
+81
-12
app/controllers/projects/cycle_analytics/events_controller.rb
...controllers/projects/cycle_analytics/events_controller.rb
+2
-2
app/serializers/analytics_build_entity.rb
app/serializers/analytics_build_entity.rb
+27
-0
app/serializers/analytics_build_serializer.rb
app/serializers/analytics_build_serializer.rb
+3
-0
lib/gitlab/cycle_analytics/events.rb
lib/gitlab/cycle_analytics/events.rb
+2
-9
lib/gitlab/light_url_builder.rb
lib/gitlab/light_url_builder.rb
+1
-1
spec/serializers/analytics_build_entity_spec.rb
spec/serializers/analytics_build_entity_spec.rb
+22
-0
spec/serializers/analytics_build_serializer_spec.rb
spec/serializers/analytics_build_serializer_spec.rb
+24
-0
No files found.
app/controllers/projects/cycle_analytics/events_controller.rb
View file @
81d0146c
...
...
@@ -35,10 +35,10 @@ class Projects::CycleAnalytics::EventsController < Projects::ApplicationControll
private
def
render_events
(
events
)
def
render_events
(
events
_list
)
respond_to
do
|
format
|
format
.
html
format
.
json
{
render
json:
{
events:
events
}
}
format
.
json
{
render
json:
{
events:
events
_list
}
}
end
end
...
...
app/serializers/analytics_build_entity.rb
0 → 100644
View file @
81d0146c
class
AnalyticsBuildEntity
<
Grape
::
Entity
include
RequestAwareEntity
expose
:name
expose
:ref
,
as: :branch
expose
:short_sha
expose
:started_at
,
as: :date
expose
:duration
,
as: :total_time
expose
:url
do
|
build
|
url_to
(
:namespace_project_build
,
build
)
end
expose
:branch_url
do
|
build
|
url_to
(
:namespace_project_tree
,
build
,
build
.
ref
)
end
expose
:commit_url
do
|
build
|
url_to
(
:namespace_project_commit
,
build
,
build
.
sha
)
end
private
def
url_to
(
route
,
build
,
id
=
nil
)
public_send
(
"
#{
route
}
_url"
,
build
.
project
.
namespace
,
build
.
project
,
id
||
build
)
end
end
app/serializers/analytics_build_serializer.rb
0 → 100644
View file @
81d0146c
class
AnalyticsBuildSerializer
<
BaseSerializer
entity
AnalyticsBuildEntity
end
lib/gitlab/cycle_analytics/events.rb
View file @
81d0146c
...
...
@@ -63,15 +63,8 @@ module Gitlab
def
parse_build_event
(
event
)
build
=
::
Ci
::
Build
.
find
(
event
[
'id'
])
event
[
'name'
]
=
build
.
name
event
[
'url'
]
=
Gitlab
::
LightUrlBuilder
.
build
(
entity: :build
,
project:
@project
,
id:
build
.
id
)
event
[
'branch'
]
=
build
.
ref
event
[
'branch_url'
]
=
Gitlab
::
LightUrlBuilder
.
build
(
entity: :branch
,
project:
@project
,
id:
build
.
ref
)
event
[
'sha'
]
=
build
.
short_sha
event
[
'commit_url'
]
=
Gitlab
::
LightUrlBuilder
.
build
(
entity: :commit
,
project:
@project
,
id:
build
.
sha
)
event
[
'date'
]
=
build
.
started_at
event
[
'total_time'
]
=
build
.
duration
event
[
'author_name'
]
=
build
.
author
.
try
(
:name
)
#event['author_name'] = build.author.try(:name)
end
def
first_time_reference_commit
(
commits
,
event
)
...
...
lib/gitlab/light_url_builder.rb
View file @
81d0146c
...
...
@@ -53,7 +53,7 @@ module Gitlab
end
def
branch_url
"
#{
project_url
(
@project
)
}
/commits/
#{
@id
}
"
namespace_project_commit_url
(
@project
.
namespace
,
@project
,
@id
)
end
def
user_url
...
...
spec/serializers/analytics_build_entity_spec.rb
0 → 100644
View file @
81d0146c
require
'spec_helper'
describe
AnalyticsBuildEntity
do
let
(
:entity
)
do
described_class
.
new
(
build
,
request:
double
)
end
context
'when build is a regular job'
do
let
(
:build
)
{
create
(
:ci_build
)
}
subject
{
entity
.
as_json
}
it
'contains url to build page and retry action'
do
expect
(
subject
).
to
include
(
:url
,
:branch_url
,
:commit_url
)
end
it
'does not contain sensitive information'
do
expect
(
subject
).
not_to
include
(
/token/
)
expect
(
subject
).
not_to
include
(
/variables/
)
end
end
end
spec/serializers/analytics_build_serializer_spec.rb
0 → 100644
View file @
81d0146c
require
'spec_helper'
describe
AnalyticsBuildSerializer
do
let
(
:serializer
)
do
described_class
.
new
(
project:
project
)
.
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
it
'it generates payload for single object'
do
expect
(
json
).
to
be_an_instance_of
Hash
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
)
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