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
beeb6461
Commit
beeb6461
authored
Nov 04, 2016
by
James Lopez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactored staging events, added missing fields and fixed specs
parent
bd31f24c
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
84 additions
and
26 deletions
+84
-26
events.rb
lib/gitlab/cycle_analytics/events.rb
+15
-11
events_fetcher.rb
lib/gitlab/cycle_analytics/events_fetcher.rb
+4
-3
query_config.rb
lib/gitlab/cycle_analytics/query_config.rb
+10
-5
events_spec.rb
spec/lib/gitlab/cycle_analytics/events_spec.rb
+55
-7
No files found.
lib/gitlab/cycle_analytics/events.rb
View file @
beeb6461
...
...
@@ -31,15 +31,7 @@ module Gitlab
def
test_events
@fetcher
.
fetch
(
stage: :test
).
each
do
|
event
|
build
=
::
Ci
::
Build
.
find
(
event
[
'id'
])
event
[
'name'
]
=
build
.
name
event
[
'url'
]
=
Gitlab
::
LightUrlBuilder
.
build
(
entity: :build_url
,
project:
@project
,
id:
build
.
id
)
event
[
'branch'
]
=
build
.
ref
event
[
'branch_url'
]
=
Gitlab
::
LightUrlBuilder
.
build
(
entity: :branch_url
,
project:
@project
,
id:
build
.
ref
)
event
[
'sha'
]
=
build
.
short_sha
event
[
'commit_url'
]
=
Gitlab
::
LightUrlBuilder
.
build
(
entity: :commit_url
,
project:
@project
,
id:
build
.
sha
)
event
[
'date'
]
=
build
.
started_at
event
[
'total_time'
]
=
build
.
duration
parse_build_event
(
event
)
end
end
...
...
@@ -49,8 +41,7 @@ module Gitlab
def
staging_events
@fetcher
.
fetch
(
stage: :staging
).
each
do
|
event
|
event
[
'total_time'
]
=
distance_of_time_in_words
(
event
[
'total_time'
].
to_f
)
event
[
'pipeline'
]
=
::
Ci
::
Pipeline
.
find_by_id
(
event
[
'ci_commit_id'
])
# we may not have a pipeline
parse_build_event
(
event
)
end
end
...
...
@@ -70,6 +61,19 @@ module Gitlab
event
.
except!
(
'author_id'
,
'author_username'
)
end
def
parse_build_event
(
event
)
build
=
::
Ci
::
Build
.
find
(
event
[
'id'
])
event
[
'name'
]
=
build
.
name
event
[
'url'
]
=
Gitlab
::
LightUrlBuilder
.
build
(
entity: :build_url
,
project:
@project
,
id:
build
.
id
)
event
[
'branch'
]
=
build
.
ref
event
[
'branch_url'
]
=
Gitlab
::
LightUrlBuilder
.
build
(
entity: :branch_url
,
project:
@project
,
id:
build
.
ref
)
event
[
'sha'
]
=
build
.
short_sha
event
[
'commit_url'
]
=
Gitlab
::
LightUrlBuilder
.
build
(
entity: :commit_url
,
project:
@project
,
id:
build
.
sha
)
event
[
'date'
]
=
build
.
started_at
event
[
'total_time'
]
=
build
.
duration
event
[
'author_name'
]
=
build
.
author
.
try
(
:name
)
end
def
first_time_reference_commit
(
commits
,
event
)
st_commit
=
YAML
.
load
(
commits
).
detect
do
|
commit
|
commit
[
'created_at'
]
==
event
[
'first_mentioned_in_commit_at'
]
...
...
lib/gitlab/cycle_analytics/events_fetcher.rb
View file @
beeb6461
...
...
@@ -19,9 +19,6 @@ module Gitlab
base_query
.
join
(
user_table
).
on
(
issue_table
[
:author_id
].
eq
(
user_table
[
:id
]))
end
alias_method
:code_custom_query
,
:issue_custom_query
alias_method
:production_custom_query
,
:issue_custom_query
def
plan_custom_query
(
base_query
)
base_query
.
join
(
mr_diff_table
).
on
(
mr_diff_table
[
:merge_request_id
].
eq
(
mr_table
[
:id
]))
end
...
...
@@ -33,6 +30,10 @@ module Gitlab
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
end
lib/gitlab/cycle_analytics/query_config.rb
View file @
beeb6461
...
...
@@ -63,17 +63,22 @@ module Gitlab
def
review
{
start_time_attrs:
mr_table
[
:created_at
],
end_time_attrs:
mr_metrics_table
[
:merged_at
],
projections:
[
mr_table
[
:title
],
mr_table
[
:iid
],
mr_table
[
:created_at
],
user_table
[
:name
],
user_table
[
:email
]]
projections:
[
mr_table
[
:title
],
mr_table
[
:iid
],
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'
)]
}
end
def
staging
{
start_time_attrs:
mr_metrics_table
[
:merged_at
],
end_time_attrs:
mr_metrics_table
[
:first_deployed_to_production_at
],
projections:
[
mr_metrics_table
[
:ci_commit_id
]]
projections:
[
build_table
[
:id
]],
order:
build_table
[
:created_at
]
}
end
...
...
spec/lib/gitlab/cycle_analytics/events_spec.rb
View file @
beeb6461
...
...
@@ -171,16 +171,28 @@ describe Gitlab::CycleAnalytics::Events do
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
end
it
'has a state'
do
expect
(
subject
.
review_events
.
first
[
'state'
]).
not_to
be_nil
end
it
'has a created_at timestamp'
do
expect
(
subject
.
review_events
.
first
[
'
created_at'
]).
to
end_with
(
'ago'
)
expect
(
subject
.
review_events
.
first
[
'
opened_at'
]).
not_to
be_nil
end
it
"has the author's email"
do
expect
(
subject
.
review_events
.
first
[
'email'
]).
to
eq
(
MergeRequest
.
first
.
author
.
email
)
it
"has the author's URL"
do
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
end
it
"has the author's name"
do
expect
(
subject
.
review_events
.
first
[
'
name'
]).
to
eq
(
MergeRequest
.
firs
t
.
author
.
name
)
expect
(
subject
.
review_events
.
first
[
'
author_name'
]).
to
eq
(
contex
t
.
author
.
name
)
end
end
...
...
@@ -194,6 +206,9 @@ describe Gitlab::CycleAnalytics::Events do
end
before
do
create
(
:ci_build
,
pipeline:
pipeline
,
status: :success
,
author:
user
)
create
(
:ci_build
,
pipeline:
pipeline
,
status: :success
,
author:
user
)
pipeline
.
run!
pipeline
.
succeed!
...
...
@@ -201,12 +216,45 @@ describe Gitlab::CycleAnalytics::Events do
deploy_master
end
it
'has the build info as a pipeline'
do
expect
(
subject
.
staging_events
.
first
[
'pipeline'
]).
to
eq
(
pipeline
)
it
'has the name'
do
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
end
it
'has the URL'
do
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
end
it
'has the branch URL'
do
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
end
it
'has the commit URL'
do
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
end
it
'has the total time'
do
expect
(
subject
.
staging_events
.
first
[
'total_time'
]).
to
eq
(
'less than a minute'
)
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
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