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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
cb353d65
Commit
cb353d65
authored
Nov 18, 2016
by
James Lopez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added new build updater, specs and refactored allowed_ids
parent
c76ef847
Changes
13
Show whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
107 additions
and
42 deletions
+107
-42
app/controllers/projects/cycle_analytics/events_controller.rb
...controllers/projects/cycle_analytics/events_controller.rb
+8
-2
lib/gitlab/cycle_analytics/author_updater.rb
lib/gitlab/cycle_analytics/author_updater.rb
+3
-21
lib/gitlab/cycle_analytics/build_updater.rb
lib/gitlab/cycle_analytics/build_updater.rb
+9
-0
lib/gitlab/cycle_analytics/code_event.rb
lib/gitlab/cycle_analytics/code_event.rb
+2
-4
lib/gitlab/cycle_analytics/issue_allowed.rb
lib/gitlab/cycle_analytics/issue_allowed.rb
+9
-0
lib/gitlab/cycle_analytics/issue_event.rb
lib/gitlab/cycle_analytics/issue_event.rb
+2
-4
lib/gitlab/cycle_analytics/merge_request_allowed.rb
lib/gitlab/cycle_analytics/merge_request_allowed.rb
+9
-0
lib/gitlab/cycle_analytics/production_event.rb
lib/gitlab/cycle_analytics/production_event.rb
+2
-4
lib/gitlab/cycle_analytics/review_event.rb
lib/gitlab/cycle_analytics/review_event.rb
+2
-4
lib/gitlab/cycle_analytics/staging_event.rb
lib/gitlab/cycle_analytics/staging_event.rb
+7
-3
lib/gitlab/cycle_analytics/updater.rb
lib/gitlab/cycle_analytics/updater.rb
+30
-0
spec/lib/gitlab/cycle_analytics/author_updater_spec.rb
spec/lib/gitlab/cycle_analytics/author_updater_spec.rb
+12
-0
spec/lib/gitlab/cycle_analytics/build_updater_spec.rb
spec/lib/gitlab/cycle_analytics/build_updater_spec.rb
+12
-0
No files found.
app/controllers/projects/cycle_analytics/events_controller.rb
View file @
cb353d65
...
@@ -5,6 +5,8 @@ module Projects
...
@@ -5,6 +5,8 @@ module Projects
before_action
:authorize_read_cycle_analytics!
before_action
:authorize_read_cycle_analytics!
before_action
:authorize_builds!
,
only:
[
:test
,
:staging
]
before_action
:authorize_builds!
,
only:
[
:test
,
:staging
]
before_action
:authorize_read_issue!
,
only:
[
:issue
,
:production
]
before_action
:authorize_read_merge_request!
,
only:
[
:code
,
:review
]
def
issue
def
issue
render_events
(
events
.
issue_events
)
render_events
(
events
.
issue_events
)
...
@@ -60,7 +62,11 @@ module Projects
...
@@ -60,7 +62,11 @@ module Projects
end
end
def
authorize_builds!
def
authorize_builds!
return
access_denied!
unless
current_user
.
can?
(
:read_build
,
project
)
return
access_denied!
unless
can?
(
current_user
,
:read_build
,
project
)
end
def
authorize_read_issue!
return
access_denied!
unless
can?
(
current_user
,
:read_issue
,
project
)
end
end
end
end
end
end
...
...
lib/gitlab/cycle_analytics/author_updater.rb
View file @
cb353d65
module
Gitlab
module
Gitlab
module
CycleAnalytics
module
CycleAnalytics
class
AuthorUpdater
class
AuthorUpdater
<
Updater
def
self
.
update!
(
*
args
)
def
self
.
update!
(
event_result
)
new
(
*
args
).
update!
new
(
event_result
,
User
,
:author
).
update!
end
def
initialize
(
event_result
)
@event_result
=
event_result
end
def
update!
@event_result
.
each
do
|
event
|
event
[
'author'
]
=
users
[
event
.
delete
(
'author_id'
).
to_i
].
first
end
end
def
user_ids
@event_result
.
map
{
|
event
|
event
[
'author_id'
]
}
end
def
users
@users
||=
User
.
find
(
user_ids
).
group_by
{
|
user
|
user
[
'id'
]
}
end
end
end
end
end
end
...
...
lib/gitlab/cycle_analytics/build_updater.rb
0 → 100644
View file @
cb353d65
module
Gitlab
module
CycleAnalytics
class
BuildUpdater
<
Updater
def
self
.
update!
(
event_result
)
new
(
event_result
,
::
Ci
::
Build
,
:build
,
'id'
).
update!
end
end
end
end
lib/gitlab/cycle_analytics/code_event.rb
View file @
cb353d65
module
Gitlab
module
Gitlab
module
CycleAnalytics
module
CycleAnalytics
class
CodeEvent
<
BaseEvent
class
CodeEvent
<
BaseEvent
include
MergeRequestAllowed
def
initialize
(
*
args
)
def
initialize
(
*
args
)
@stage
=
:code
@stage
=
:code
@start_time_attrs
=
issue_metrics_table
[
:first_mentioned_in_commit_at
]
@start_time_attrs
=
issue_metrics_table
[
:first_mentioned_in_commit_at
]
...
@@ -21,10 +23,6 @@ module Gitlab
...
@@ -21,10 +23,6 @@ module Gitlab
def
serialize
(
event
)
def
serialize
(
event
)
AnalyticsMergeRequestSerializer
.
new
(
project:
@project
).
represent
(
event
).
as_json
AnalyticsMergeRequestSerializer
.
new
(
project:
@project
).
represent
(
event
).
as_json
end
end
def
allowed_ids
@allowed_ids
||=
MergeRequestsFinder
.
new
(
@options
[
:current_user
],
project_id:
@project
.
id
).
execute
.
where
(
id:
event_result_ids
).
pluck
(
:id
)
end
end
end
end
end
end
end
lib/gitlab/cycle_analytics/issue_allowed.rb
0 → 100644
View file @
cb353d65
module
Gitlab
module
CycleAnalytics
module
IssueAllowed
def
allowed_ids
@allowed_ids
||=
IssuesFinder
.
new
(
@options
[
:current_user
],
project_id:
@project
.
id
).
execute
.
where
(
id:
event_result_ids
).
pluck
(
:id
)
end
end
end
end
lib/gitlab/cycle_analytics/issue_event.rb
View file @
cb353d65
module
Gitlab
module
Gitlab
module
CycleAnalytics
module
CycleAnalytics
class
IssueEvent
<
BaseEvent
class
IssueEvent
<
BaseEvent
include
IssueAllowed
def
initialize
(
*
args
)
def
initialize
(
*
args
)
@stage
=
:issue
@stage
=
:issue
@start_time_attrs
=
issue_table
[
:created_at
]
@start_time_attrs
=
issue_table
[
:created_at
]
...
@@ -20,10 +22,6 @@ module Gitlab
...
@@ -20,10 +22,6 @@ module Gitlab
def
serialize
(
event
)
def
serialize
(
event
)
AnalyticsIssueSerializer
.
new
(
project:
@project
).
represent
(
event
).
as_json
AnalyticsIssueSerializer
.
new
(
project:
@project
).
represent
(
event
).
as_json
end
end
def
allowed_ids
@allowed_ids
||=
IssuesFinder
.
new
(
@options
[
:current_user
],
project_id:
@project
.
id
).
execute
.
where
(
id:
event_result_ids
).
pluck
(
:id
)
end
end
end
end
end
end
end
lib/gitlab/cycle_analytics/merge_request_allowed.rb
0 → 100644
View file @
cb353d65
module
Gitlab
module
CycleAnalytics
module
MergeRequestAllowed
def
allowed_ids
@allowed_ids
||=
MergeRequestsFinder
.
new
(
@options
[
:current_user
],
project_id:
@project
.
id
).
execute
.
where
(
id:
event_result_ids
).
pluck
(
:id
)
end
end
end
end
lib/gitlab/cycle_analytics/production_event.rb
View file @
cb353d65
module
Gitlab
module
Gitlab
module
CycleAnalytics
module
CycleAnalytics
class
ProductionEvent
<
BaseEvent
class
ProductionEvent
<
BaseEvent
include
IssueAllowed
def
initialize
(
*
args
)
def
initialize
(
*
args
)
@stage
=
:production
@stage
=
:production
@start_time_attrs
=
issue_table
[
:created_at
]
@start_time_attrs
=
issue_table
[
:created_at
]
...
@@ -19,10 +21,6 @@ module Gitlab
...
@@ -19,10 +21,6 @@ module Gitlab
def
serialize
(
event
)
def
serialize
(
event
)
AnalyticsIssueSerializer
.
new
(
project:
@project
).
represent
(
event
).
as_json
AnalyticsIssueSerializer
.
new
(
project:
@project
).
represent
(
event
).
as_json
end
end
def
allowed_ids
@allowed_ids
||=
IssuesFinder
.
new
(
@options
[
:current_user
],
project_id:
@project
.
id
).
execute
.
where
(
id:
event_result_ids
).
pluck
(
:id
)
end
end
end
end
end
end
end
lib/gitlab/cycle_analytics/review_event.rb
View file @
cb353d65
module
Gitlab
module
Gitlab
module
CycleAnalytics
module
CycleAnalytics
class
ReviewEvent
<
BaseEvent
class
ReviewEvent
<
BaseEvent
include
MergeRequestAllowed
def
initialize
(
*
args
)
def
initialize
(
*
args
)
@stage
=
:review
@stage
=
:review
@start_time_attrs
=
mr_table
[
:created_at
]
@start_time_attrs
=
mr_table
[
:created_at
]
...
@@ -18,10 +20,6 @@ module Gitlab
...
@@ -18,10 +20,6 @@ module Gitlab
def
serialize
(
event
)
def
serialize
(
event
)
AnalyticsMergeRequestSerializer
.
new
(
project:
@project
).
represent
(
event
).
as_json
AnalyticsMergeRequestSerializer
.
new
(
project:
@project
).
represent
(
event
).
as_json
end
end
def
allowed_ids
@allowed_ids
||=
MergeRequestsFinder
.
new
(
@options
[
:current_user
],
project_id:
@project
.
id
).
execute
.
where
(
id:
event_result_ids
).
pluck
(
:id
)
end
end
end
end
end
end
end
lib/gitlab/cycle_analytics/staging_event.rb
View file @
cb353d65
...
@@ -11,6 +11,12 @@ module Gitlab
...
@@ -11,6 +11,12 @@ module Gitlab
super
(
*
args
)
super
(
*
args
)
end
end
def
fetch
BuildUpdater
.
update!
(
event_result
)
super
end
def
custom_query
(
base_query
)
def
custom_query
(
base_query
)
base_query
.
join
(
build_table
).
on
(
mr_metrics_table
[
:pipeline_id
].
eq
(
build_table
[
:commit_id
]))
base_query
.
join
(
build_table
).
on
(
mr_metrics_table
[
:pipeline_id
].
eq
(
build_table
[
:commit_id
]))
end
end
...
@@ -18,9 +24,7 @@ module Gitlab
...
@@ -18,9 +24,7 @@ module Gitlab
private
private
def
serialize
(
event
)
def
serialize
(
event
)
build
=
::
Ci
::
Build
.
find
(
event
[
'id'
])
AnalyticsBuildSerializer
.
new
.
represent
(
event
[
'build'
]).
as_json
AnalyticsBuildSerializer
.
new
.
represent
(
build
).
as_json
end
end
end
end
end
end
...
...
lib/gitlab/cycle_analytics/updater.rb
0 → 100644
View file @
cb353d65
module
Gitlab
module
CycleAnalytics
class
Updater
def
self
.
update!
(
*
args
)
new
(
*
args
).
update!
end
def
initialize
(
event_result
,
update_klass
,
update_key
,
column
=
nil
)
@event_result
=
event_result
@update_klass
=
update_klass
@update_key
=
update_key
.
to_s
@column
=
column
||
"
#{
@update_key
}
_id"
end
def
update!
@event_result
.
each
do
|
event
|
event
[
@update_key
]
=
items
[
event
.
delete
(
@column
).
to_i
].
first
end
end
def
result_ids
@event_result
.
map
{
|
event
|
event
[
@column
]
}
end
def
items
@items
||=
@update_klass
.
find
(
result_ids
).
group_by
{
|
item
|
item
[
'id'
]
}
end
end
end
end
spec/lib/gitlab/cycle_analytics/author_updater_spec.rb
0 → 100644
View file @
cb353d65
require
'spec_helper'
describe
Gitlab
::
CycleAnalytics
::
AuthorUpdater
do
let
(
:user
)
{
create
(
:user
)
}
let
(
:events
)
{
[{
'author_id'
=>
user
.
id
}]
}
it
'maps the correct user'
do
described_class
.
update!
(
events
)
expect
(
events
.
first
[
'author'
]).
to
eq
(
user
)
end
end
spec/lib/gitlab/cycle_analytics/build_updater_spec.rb
0 → 100644
View file @
cb353d65
require
'spec_helper'
describe
Gitlab
::
CycleAnalytics
::
BuildUpdater
do
let
(
:build
)
{
create
(
:ci_build
)
}
let
(
:events
)
{
[{
'id'
=>
build
.
id
}]
}
it
'maps the correct user'
do
described_class
.
update!
(
events
)
expect
(
events
.
first
[
'build'
]).
to
eq
(
build
)
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