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
f5b792e2
Commit
f5b792e2
authored
Nov 18, 2016
by
James Lopez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactored updater and updated specs
parent
0aa47788
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
35 additions
and
60 deletions
+35
-60
app/controllers/projects/cycle_analytics/events_controller.rb
...controllers/projects/cycle_analytics/events_controller.rb
+1
-9
lib/gitlab/cycle_analytics/author_updater.rb
lib/gitlab/cycle_analytics/author_updater.rb
+0
-9
lib/gitlab/cycle_analytics/base_event.rb
lib/gitlab/cycle_analytics/base_event.rb
+1
-1
lib/gitlab/cycle_analytics/build_updater.rb
lib/gitlab/cycle_analytics/build_updater.rb
+0
-9
lib/gitlab/cycle_analytics/staging_event.rb
lib/gitlab/cycle_analytics/staging_event.rb
+1
-1
lib/gitlab/cycle_analytics/updater.rb
lib/gitlab/cycle_analytics/updater.rb
+7
-7
spec/lib/gitlab/cycle_analytics/author_updater_spec.rb
spec/lib/gitlab/cycle_analytics/author_updater_spec.rb
+0
-12
spec/lib/gitlab/cycle_analytics/build_updater_spec.rb
spec/lib/gitlab/cycle_analytics/build_updater_spec.rb
+0
-12
spec/lib/gitlab/cycle_analytics/updater_spec.rb
spec/lib/gitlab/cycle_analytics/updater_spec.rb
+25
-0
No files found.
app/controllers/projects/cycle_analytics/events_controller.rb
View file @
f5b792e2
...
...
@@ -4,7 +4,7 @@ module Projects
include
CycleAnalyticsParams
before_action
:authorize_read_cycle_analytics!
before_action
:authorize_
builds
!
,
only:
[
:test
,
:staging
]
before_action
:authorize_
read_build
!
,
only:
[
:test
,
:staging
]
before_action
:authorize_read_issue!
,
only:
[
:issue
,
:production
]
before_action
:authorize_read_merge_request!
,
only:
[
:code
,
:review
]
...
...
@@ -60,14 +60,6 @@ module Projects
params
[
:events
].
slice
(
:start_date
,
:branch_name
)
end
def
authorize_builds!
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
lib/gitlab/cycle_analytics/author_updater.rb
deleted
100644 → 0
View file @
0aa47788
module
Gitlab
module
CycleAnalytics
class
AuthorUpdater
<
Updater
def
self
.
update!
(
event_result
)
new
(
event_result
,
User
,
:author
).
update!
end
end
end
end
lib/gitlab/cycle_analytics/base_event.rb
View file @
f5b792e2
...
...
@@ -30,7 +30,7 @@ module Gitlab
def
update_author!
return
unless
event_result
.
any?
&&
event_result
.
first
[
'author_id'
]
AuthorUpdater
.
update!
(
event_result
)
Updater
.
update!
(
event_result
,
from:
'author_id'
,
to:
'author'
,
klass:
User
)
end
def
event_result
...
...
lib/gitlab/cycle_analytics/build_updater.rb
deleted
100644 → 0
View file @
0aa47788
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/staging_event.rb
View file @
f5b792e2
...
...
@@ -12,7 +12,7 @@ module Gitlab
end
def
fetch
BuildUpdater
.
update!
(
event_result
)
Updater
.
update!
(
event_result
,
from:
'id'
,
to:
'build'
,
klass:
::
Ci
::
Build
)
super
end
...
...
lib/gitlab/cycle_analytics/updater.rb
View file @
f5b792e2
...
...
@@ -5,25 +5,25 @@ module Gitlab
new
(
*
args
).
update!
end
def
initialize
(
event_result
,
update_klass
,
update_key
,
column
=
nil
)
def
initialize
(
event_result
,
from
:,
to
:,
klass
:
)
@event_result
=
event_result
@
update_klass
=
update_
klass
@
update_key
=
update_key
.
to_s
@
column
=
column
||
"
#{
@update_key
}
_id"
@
klass
=
klass
@
from
=
from
@
to
=
to
end
def
update!
@event_result
.
each
do
|
event
|
event
[
@
update_key
]
=
items
[
event
.
delete
(
@column
).
to_i
].
first
event
[
@
to
]
=
items
[
event
.
delete
(
@from
).
to_i
].
first
end
end
def
result_ids
@event_result
.
map
{
|
event
|
event
[
@
column
]
}
@event_result
.
map
{
|
event
|
event
[
@
from
]
}
end
def
items
@items
||=
@
update_
klass
.
find
(
result_ids
).
group_by
{
|
item
|
item
[
'id'
]
}
@items
||=
@klass
.
find
(
result_ids
).
group_by
{
|
item
|
item
[
'id'
]
}
end
end
end
...
...
spec/lib/gitlab/cycle_analytics/author_updater_spec.rb
deleted
100644 → 0
View file @
0aa47788
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
deleted
100644 → 0
View file @
0aa47788
require
'spec_helper'
describe
Gitlab
::
CycleAnalytics
::
BuildUpdater
do
let
(
:build
)
{
create
(
:ci_build
)
}
let
(
:events
)
{
[{
'id'
=>
build
.
id
}]
}
it
'maps the correct build'
do
described_class
.
update!
(
events
)
expect
(
events
.
first
[
'build'
]).
to
eq
(
build
)
end
end
spec/lib/gitlab/cycle_analytics/updater_spec.rb
0 → 100644
View file @
f5b792e2
require
'spec_helper'
describe
Gitlab
::
CycleAnalytics
::
Updater
do
describe
'updates authors'
do
let
(
:user
)
{
create
(
:user
)
}
let
(
:events
)
{
[{
'author_id'
=>
user
.
id
}]
}
it
'maps the correct user'
do
described_class
.
update!
(
events
,
from:
'author_id'
,
to:
'author'
,
klass:
User
)
expect
(
events
.
first
[
'author'
]).
to
eq
(
user
)
end
end
describe
'updates builds'
do
let
(
:build
)
{
create
(
:ci_build
)
}
let
(
:events
)
{
[{
'id'
=>
build
.
id
}]
}
it
'maps the correct build'
do
described_class
.
update!
(
events
,
from:
'id'
,
to:
'build'
,
klass:
::
Ci
::
Build
)
expect
(
events
.
first
[
'build'
]).
to
eq
(
build
)
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