Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
projects.thm.de
GitLab
Commits
3b179bc3
Commit
3b179bc3
authored
Nov 14, 2016
by
James Lopez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
WIP - refactored events to use build serializer, related spec passing
parent
81d0146c
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
79 additions
and
68 deletions
+79
-68
app/serializers/analytics_build_entity.rb
app/serializers/analytics_build_entity.rb
+10
-4
lib/gitlab/cycle_analytics/events.rb
lib/gitlab/cycle_analytics/events.rb
+3
-3
spec/lib/gitlab/cycle_analytics/events_spec.rb
spec/lib/gitlab/cycle_analytics/events_spec.rb
+59
-59
spec/serializers/analytics_build_entity_spec.rb
spec/serializers/analytics_build_entity_spec.rb
+7
-2
No files found.
app/serializers/analytics_build_entity.rb
View file @
3b179bc3
...
...
@@ -2,17 +2,23 @@ class AnalyticsBuildEntity < Grape::Entity
include
RequestAwareEntity
expose
:name
expose
:id
expose
:ref
,
as: :branch
expose
:short_sha
expose
:started_at
,
as: :date
expose
:duration
,
as: :total_time
expose
:author
,
using:
UserEntity
expose
:url
do
|
build
|
url_to
(
:namespace_project_build
,
build
)
expose
:branch
do
expose
:ref
,
as: :name
expose
:url
do
|
build
|
url_to
(
:namespace_project_tree
,
build
,
build
.
ref
)
end
end
expose
:
branch_
url
do
|
build
|
url_to
(
:namespace_project_
tree
,
build
,
build
.
ref
)
expose
:url
do
|
build
|
url_to
(
:namespace_project_build
,
build
)
end
expose
:commit_url
do
|
build
|
...
...
lib/gitlab/cycle_analytics/events.rb
View file @
3b179bc3
...
...
@@ -30,7 +30,7 @@ def code_events
end
def
test_events
@fetcher
.
fetch
(
stage: :test
).
each
do
|
event
|
@fetcher
.
fetch
(
stage: :test
).
map
do
|
event
|
parse_build_event
(
event
)
end
end
...
...
@@ -40,7 +40,7 @@ def review_events
end
def
staging_events
@fetcher
.
fetch
(
stage: :staging
).
each
do
|
event
|
@fetcher
.
fetch
(
stage: :staging
).
map
do
|
event
|
parse_build_event
(
event
)
end
end
...
...
@@ -64,7 +64,7 @@ def parse_event(event, entity: :issue)
def
parse_build_event
(
event
)
build
=
::
Ci
::
Build
.
find
(
event
[
'id'
])
#event['author_name'] =
build.a
uthor.try(:name)
AnalyticsBuildSerializer
.
new
(
project:
@project
).
represent
(
build
)
.
a
s_json
end
def
first_time_reference_commit
(
commits
,
event
)
...
...
spec/lib/gitlab/cycle_analytics/events_spec.rb
View file @
3b179bc3
...
...
@@ -14,61 +14,61 @@
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
]).
to
eq
(
'2 days'
)
end
it
'has a title'
do
expect
(
subject
.
issue_events
.
first
[
'
title
'
]).
to
eq
(
context
.
title
)
expect
(
subject
.
issue_events
.
first
[
:
title
]).
to
eq
(
context
.
title
)
end
it
'has the URL'
do
expect
(
subject
.
issue_events
.
first
[
'
url
'
]).
not_to
be_nil
expect
(
subject
.
issue_events
.
first
[
:
url
]).
not_to
be_nil
end
it
'has an iid'
do
expect
(
subject
.
issue_events
.
first
[
'
iid
'
]).
to
eq
(
context
.
iid
.
to_s
)
expect
(
subject
.
issue_events
.
first
[
:
iid
]).
to
eq
(
context
.
iid
.
to_s
)
end
it
'has a created_at timestamp'
do
expect
(
subject
.
issue_events
.
first
[
'
created_at
'
]).
to
end_with
(
'ago'
)
expect
(
subject
.
issue_events
.
first
[
:
created_at
]).
to
end_with
(
'ago'
)
end
it
"has the author's URL"
do
expect
(
subject
.
issue_events
.
first
[
'
author_profile_url
'
]).
not_to
be_nil
expect
(
subject
.
issue_events
.
first
[
:
author_profile_url
]).
not_to
be_nil
end
it
"has the author's avatar URL"
do
expect
(
subject
.
issue_events
.
first
[
'
author_avatar_url
'
]).
not_to
be_nil
expect
(
subject
.
issue_events
.
first
[
:
author_avatar_url
]).
not_to
be_nil
end
it
"has the author's name"
do
expect
(
subject
.
issue_events
.
first
[
'
author_name
'
]).
to
eq
(
context
.
author
.
name
)
expect
(
subject
.
issue_events
.
first
[
:
author_name
]).
to
eq
(
context
.
author
.
name
)
end
end
describe
'#plan_events'
do
it
'has a title'
do
expect
(
subject
.
plan_events
.
first
[
'
title
'
]).
not_to
be_nil
expect
(
subject
.
plan_events
.
first
[
:
title
]).
not_to
be_nil
end
it
'has a sha short ID'
do
expect
(
subject
.
plan_events
.
first
[
'
sha
'
]).
not_to
be_nil
expect
(
subject
.
plan_events
.
first
[
:
sha
]).
not_to
be_nil
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
]).
to
eq
(
'less than a minute'
)
end
it
"has the author's URL"
do
expect
(
subject
.
plan_events
.
first
[
'
author_profile_url
'
]).
not_to
be_nil
expect
(
subject
.
plan_events
.
first
[
:
author_profile_url
]).
not_to
be_nil
end
it
"has the author's avatar URL"
do
expect
(
subject
.
plan_events
.
first
[
'
author_avatar_url
'
]).
not_to
be_nil
expect
(
subject
.
plan_events
.
first
[
:
author_avatar_url
]).
not_to
be_nil
end
it
"has the author's name"
do
expect
(
subject
.
plan_events
.
first
[
'
author_name
'
]).
not_to
be_nil
expect
(
subject
.
plan_events
.
first
[
:
author_name
]).
not_to
be_nil
end
end
...
...
@@ -78,31 +78,31 @@
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
]).
to
eq
(
'less than a minute'
)
end
it
'has a title'
do
expect
(
subject
.
code_events
.
first
[
'
title
'
]).
to
eq
(
'Awesome merge_request'
)
expect
(
subject
.
code_events
.
first
[
:
title
]).
to
eq
(
'Awesome merge_request'
)
end
it
'has an iid'
do
expect
(
subject
.
code_events
.
first
[
'
iid
'
]).
to
eq
(
context
.
iid
.
to_s
)
expect
(
subject
.
code_events
.
first
[
:
iid
]).
to
eq
(
context
.
iid
.
to_s
)
end
it
'has a created_at timestamp'
do
expect
(
subject
.
code_events
.
first
[
'
created_at
'
]).
to
end_with
(
'ago'
)
expect
(
subject
.
code_events
.
first
[
:
created_at
]).
to
end_with
(
'ago'
)
end
it
"has the author's URL"
do
expect
(
subject
.
code_events
.
first
[
'
author_profile_url
'
]).
not_to
be_nil
expect
(
subject
.
code_events
.
first
[
:
author_profile_url
]).
not_to
be_nil
end
it
"has the author's avatar URL"
do
expect
(
subject
.
code_events
.
first
[
'
author_avatar_url
'
]).
not_to
be_nil
expect
(
subject
.
code_events
.
first
[
:
author_avatar_url
]).
not_to
be_nil
end
it
"has the author's name"
do
expect
(
subject
.
code_events
.
first
[
'
author_name
'
]).
to
eq
(
context
.
author
.
name
)
expect
(
subject
.
code_events
.
first
[
:
author_name
]).
to
eq
(
context
.
author
.
name
)
end
end
...
...
@@ -116,47 +116,47 @@
end
before
do
create
(
:ci_build
,
pipeline:
pipeline
,
status: :success
)
create
(
:ci_build
,
pipeline:
pipeline
,
status: :success
)
create
(
:ci_build
,
pipeline:
pipeline
,
status: :success
,
author:
user
)
create
(
:ci_build
,
pipeline:
pipeline
,
status: :success
,
author:
user
)
pipeline
.
run!
pipeline
.
succeed!
end
it
'has the name'
do
expect
(
subject
.
test_events
.
first
[
'
name
'
]).
not_to
be_nil
expect
(
subject
.
test_events
.
first
[
:
name
]).
not_to
be_nil
end
it
'has the ID'
do
expect
(
subject
.
test_events
.
first
[
'
id
'
]).
not_to
be_nil
expect
(
subject
.
test_events
.
first
[
:
id
]).
not_to
be_nil
end
it
'has the URL'
do
expect
(
subject
.
test_events
.
first
[
'
url
'
]).
not_to
be_nil
expect
(
subject
.
test_events
.
first
[
:
url
]).
not_to
be_nil
end
it
'has the branch name'
do
expect
(
subject
.
test_events
.
first
[
'
branch
'
]).
not_to
be_nil
expect
(
subject
.
test_events
.
first
[
:
branch
]).
not_to
be_nil
end
it
'has the branch URL'
do
expect
(
subject
.
test_events
.
first
[
'
branch
_
url
'
]).
not_to
be_nil
expect
(
subject
.
test_events
.
first
[
:
branch
][
:
url
]).
not_to
be_nil
end
it
'has the short SHA'
do
expect
(
subject
.
test_events
.
first
[
'
sha
'
]).
not_to
be_nil
expect
(
subject
.
test_events
.
first
[
:short_
sha
]).
not_to
be_nil
end
it
'has the commit URL'
do
expect
(
subject
.
test_events
.
first
[
'
commit_url
'
]).
not_to
be_nil
expect
(
subject
.
test_events
.
first
[
:
commit_url
]).
not_to
be_nil
end
it
'has the date'
do
expect
(
subject
.
test_events
.
first
[
'
date
'
]).
not_to
be_nil
expect
(
subject
.
test_events
.
first
[
:
date
]).
not_to
be_nil
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_nil
end
end
...
...
@@ -164,39 +164,39 @@
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
]).
to
eq
(
'less than a minute'
)
end
it
'has a title'
do
expect
(
subject
.
review_events
.
first
[
'
title
'
]).
to
eq
(
'Awesome merge_request'
)
expect
(
subject
.
review_events
.
first
[
:
title
]).
to
eq
(
'Awesome merge_request'
)
end
it
'has an iid'
do
expect
(
subject
.
review_events
.
first
[
'
iid
'
]).
to
eq
(
context
.
iid
.
to_s
)
expect
(
subject
.
review_events
.
first
[
:
iid
]).
to
eq
(
context
.
iid
.
to_s
)
end
it
'has the URL'
do
expect
(
subject
.
review_events
.
first
[
'
url
'
]).
not_to
be_nil
expect
(
subject
.
review_events
.
first
[
:
url
]).
not_to
be_nil
end
it
'has a state'
do
expect
(
subject
.
review_events
.
first
[
'
state
'
]).
not_to
be_nil
expect
(
subject
.
review_events
.
first
[
:
state
]).
not_to
be_nil
end
it
'has a created_at timestamp'
do
expect
(
subject
.
review_events
.
first
[
'
opened_at
'
]).
not_to
be_nil
expect
(
subject
.
review_events
.
first
[
:
opened_at
]).
not_to
be_nil
end
it
"has the author's URL"
do
expect
(
subject
.
review_events
.
first
[
'
author_profile_url
'
]).
not_to
be_nil
expect
(
subject
.
review_events
.
first
[
:
author_profile_url
]).
not_to
be_nil
end
it
"has the author's avatar URL"
do
expect
(
subject
.
review_events
.
first
[
'
author_avatar_url
'
]).
not_to
be_nil
expect
(
subject
.
review_events
.
first
[
:
author_avatar_url
]).
not_to
be_nil
end
it
"has the author's name"
do
expect
(
subject
.
review_events
.
first
[
'
author_name
'
]).
to
eq
(
MergeRequest
.
first
.
author
.
name
)
expect
(
subject
.
review_events
.
first
[
:
author_name
]).
to
eq
(
MergeRequest
.
first
.
author
.
name
)
end
end
...
...
@@ -221,43 +221,43 @@
end
it
'has the name'
do
expect
(
subject
.
staging_events
.
first
[
'
name
'
]).
not_to
be_nil
expect
(
subject
.
staging_events
.
first
[
:
name
]).
not_to
be_nil
end
it
'has the ID'
do
expect
(
subject
.
staging_events
.
first
[
'
id
'
]).
not_to
be_nil
expect
(
subject
.
staging_events
.
first
[
:
id
]).
not_to
be_nil
end
it
'has the URL'
do
expect
(
subject
.
staging_events
.
first
[
'
url
'
]).
not_to
be_nil
expect
(
subject
.
staging_events
.
first
[
:
url
]).
not_to
be_nil
end
it
'has the branch name'
do
expect
(
subject
.
staging_events
.
first
[
'
branch
'
]).
not_to
be_nil
expect
(
subject
.
staging_events
.
first
[
:
branch
]).
not_to
be_nil
end
it
'has the branch URL'
do
expect
(
subject
.
staging_events
.
first
[
'
branch_url
'
]).
not_to
be_nil
expect
(
subject
.
staging_events
.
first
[
:
branch_url
]).
not_to
be_nil
end
it
'has the short SHA'
do
expect
(
subject
.
staging_events
.
first
[
'
sha
'
]).
not_to
be_nil
expect
(
subject
.
staging_events
.
first
[
:
sha
]).
not_to
be_nil
end
it
'has the commit URL'
do
expect
(
subject
.
staging_events
.
first
[
'
commit_url
'
]).
not_to
be_nil
expect
(
subject
.
staging_events
.
first
[
:
commit_url
]).
not_to
be_nil
end
it
'has the date'
do
expect
(
subject
.
staging_events
.
first
[
'
date
'
]).
not_to
be_nil
expect
(
subject
.
staging_events
.
first
[
:
date
]).
not_to
be_nil
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_nil
end
it
'has the author name'
do
expect
(
subject
.
staging_events
.
first
[
'
author_name
'
]).
not_to
be_nil
expect
(
subject
.
staging_events
.
first
[
:
author_name
]).
not_to
be_nil
end
end
...
...
@@ -270,35 +270,35 @@
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
]).
to
eq
(
'2 days'
)
end
it
'has a title'
do
expect
(
subject
.
production_events
.
first
[
'
title
'
]).
to
eq
(
context
.
title
)
expect
(
subject
.
production_events
.
first
[
:
title
]).
to
eq
(
context
.
title
)
end
it
'has the URL'
do
expect
(
subject
.
production_events
.
first
[
'
url
'
]).
not_to
be_nil
expect
(
subject
.
production_events
.
first
[
:
url
]).
not_to
be_nil
end
it
'has an iid'
do
expect
(
subject
.
production_events
.
first
[
'
iid
'
]).
to
eq
(
context
.
iid
.
to_s
)
expect
(
subject
.
production_events
.
first
[
:
iid
]).
to
eq
(
context
.
iid
.
to_s
)
end
it
'has a created_at timestamp'
do
expect
(
subject
.
production_events
.
first
[
'
created_at
'
]).
to
end_with
(
'ago'
)
expect
(
subject
.
production_events
.
first
[
:
created_at
]).
to
end_with
(
'ago'
)
end
it
"has the author's URL"
do
expect
(
subject
.
production_events
.
first
[
'
author_profile_url
'
]).
not_to
be_nil
expect
(
subject
.
production_events
.
first
[
:
author_profile_url
]).
not_to
be_nil
end
it
"has the author's avatar URL"
do
expect
(
subject
.
production_events
.
first
[
'
author_avatar_url
'
]).
not_to
be_nil
expect
(
subject
.
production_events
.
first
[
:
author_avatar_url
]).
not_to
be_nil
end
it
"has the author's name"
do
expect
(
subject
.
production_events
.
first
[
'
author_name
'
]).
to
eq
(
context
.
author
.
name
)
expect
(
subject
.
production_events
.
first
[
:
author_name
]).
to
eq
(
context
.
author
.
name
)
end
end
...
...
spec/serializers/analytics_build_entity_spec.rb
View file @
3b179bc3
...
...
@@ -6,14 +6,19 @@
end
context
'when build is a regular job'
do
let
(
:build
)
{
create
(
:ci_build
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:build
)
{
create
(
:ci_build
,
author:
user
)
}
subject
{
entity
.
as_json
}
it
'contains
url to build page and retry action
'
do
it
'contains
URLs
'
do
expect
(
subject
).
to
include
(
:url
,
:branch_url
,
:commit_url
)
end
it
'contains the author'
do
expect
(
subject
).
to
include
(
:author
)
end
it
'does not contain sensitive information'
do
expect
(
subject
).
not_to
include
(
/token/
)
expect
(
subject
).
not_to
include
(
/variables/
)
...
...
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