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
Léo-Paul Géneau
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
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
84 additions
and
26 deletions
+84
-26
lib/gitlab/cycle_analytics/events.rb
lib/gitlab/cycle_analytics/events.rb
+15
-11
lib/gitlab/cycle_analytics/events_fetcher.rb
lib/gitlab/cycle_analytics/events_fetcher.rb
+4
-3
lib/gitlab/cycle_analytics/query_config.rb
lib/gitlab/cycle_analytics/query_config.rb
+10
-5
spec/lib/gitlab/cycle_analytics/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
...
@@ -31,15 +31,7 @@ module Gitlab
def
test_events
def
test_events
@fetcher
.
fetch
(
stage: :test
).
each
do
|
event
|
@fetcher
.
fetch
(
stage: :test
).
each
do
|
event
|
build
=
::
Ci
::
Build
.
find
(
event
[
'id'
])
parse_build_event
(
event
)
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
end
end
end
end
...
@@ -49,8 +41,7 @@ module Gitlab
...
@@ -49,8 +41,7 @@ module Gitlab
def
staging_events
def
staging_events
@fetcher
.
fetch
(
stage: :staging
).
each
do
|
event
|
@fetcher
.
fetch
(
stage: :staging
).
each
do
|
event
|
event
[
'total_time'
]
=
distance_of_time_in_words
(
event
[
'total_time'
].
to_f
)
parse_build_event
(
event
)
event
[
'pipeline'
]
=
::
Ci
::
Pipeline
.
find_by_id
(
event
[
'ci_commit_id'
])
# we may not have a pipeline
end
end
end
end
...
@@ -70,6 +61,19 @@ module Gitlab
...
@@ -70,6 +61,19 @@ module Gitlab
event
.
except!
(
'author_id'
,
'author_username'
)
event
.
except!
(
'author_id'
,
'author_username'
)
end
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
)
def
first_time_reference_commit
(
commits
,
event
)
st_commit
=
YAML
.
load
(
commits
).
detect
do
|
commit
|
st_commit
=
YAML
.
load
(
commits
).
detect
do
|
commit
|
commit
[
'created_at'
]
==
event
[
'first_mentioned_in_commit_at'
]
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
...
@@ -19,9 +19,6 @@ module Gitlab
base_query
.
join
(
user_table
).
on
(
issue_table
[
:author_id
].
eq
(
user_table
[
:id
]))
base_query
.
join
(
user_table
).
on
(
issue_table
[
:author_id
].
eq
(
user_table
[
:id
]))
end
end
alias_method
:code_custom_query
,
:issue_custom_query
alias_method
:production_custom_query
,
:issue_custom_query
def
plan_custom_query
(
base_query
)
def
plan_custom_query
(
base_query
)
base_query
.
join
(
mr_diff_table
).
on
(
mr_diff_table
[
:merge_request_id
].
eq
(
mr_table
[
:id
]))
base_query
.
join
(
mr_diff_table
).
on
(
mr_diff_table
[
:merge_request_id
].
eq
(
mr_table
[
:id
]))
end
end
...
@@ -33,6 +30,10 @@ module Gitlab
...
@@ -33,6 +30,10 @@ module Gitlab
def
test_custom_query
(
base_query
)
def
test_custom_query
(
base_query
)
base_query
.
join
(
build_table
).
on
(
mr_metrics_table
[
:ci_commit_id
].
eq
(
build_table
[
:commit_id
]))
base_query
.
join
(
build_table
).
on
(
mr_metrics_table
[
:ci_commit_id
].
eq
(
build_table
[
:commit_id
]))
end
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
end
end
end
lib/gitlab/cycle_analytics/query_config.rb
View file @
beeb6461
...
@@ -63,17 +63,22 @@ module Gitlab
...
@@ -63,17 +63,22 @@ module Gitlab
def
review
def
review
{
start_time_attrs:
mr_table
[
:created_at
],
{
start_time_attrs:
mr_table
[
:created_at
],
end_time_attrs:
mr_metrics_table
[
:merged_at
],
end_time_attrs:
mr_metrics_table
[
:merged_at
],
projections:
[
mr_table
[
:title
],
mr_table
[
:iid
],
projections:
[
mr_table
[
:title
],
mr_table
[
:created_at
],
mr_table
[
:iid
],
user_table
[
:name
],
mr_table
[
:id
],
user_table
[
:email
]]
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
end
def
staging
def
staging
{
start_time_attrs:
mr_metrics_table
[
:merged_at
],
{
start_time_attrs:
mr_metrics_table
[
:merged_at
],
end_time_attrs:
mr_metrics_table
[
:first_deployed_to_production_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
end
...
...
spec/lib/gitlab/cycle_analytics/events_spec.rb
View file @
beeb6461
...
@@ -171,16 +171,28 @@ describe Gitlab::CycleAnalytics::Events do
...
@@ -171,16 +171,28 @@ describe Gitlab::CycleAnalytics::Events 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
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
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
end
it
"has the author's email"
do
it
"has the author's URL"
do
expect
(
subject
.
review_events
.
first
[
'email'
]).
to
eq
(
MergeRequest
.
first
.
author
.
email
)
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
end
it
"has the author's name"
do
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
end
end
...
@@ -194,6 +206,9 @@ describe Gitlab::CycleAnalytics::Events do
...
@@ -194,6 +206,9 @@ describe Gitlab::CycleAnalytics::Events do
end
end
before
do
before
do
create
(
:ci_build
,
pipeline:
pipeline
,
status: :success
,
author:
user
)
create
(
:ci_build
,
pipeline:
pipeline
,
status: :success
,
author:
user
)
pipeline
.
run!
pipeline
.
run!
pipeline
.
succeed!
pipeline
.
succeed!
...
@@ -201,12 +216,45 @@ describe Gitlab::CycleAnalytics::Events do
...
@@ -201,12 +216,45 @@ describe Gitlab::CycleAnalytics::Events do
deploy_master
deploy_master
end
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
end
it
'has the total time'
do
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
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