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
Jérome Perrin
gitlab-ce
Commits
192918cd
Commit
192918cd
authored
Nov 07, 2016
by
James Lopez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactored duplicated code in controller, updated JSON array naming and fixed specs
parent
b4bb33c5
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
36 additions
and
49 deletions
+36
-49
app/controllers/concerns/cycle_analytics_params.rb
app/controllers/concerns/cycle_analytics_params.rb
+7
-0
app/controllers/projects/cycle_analytics/events_controller.rb
...controllers/projects/cycle_analytics/events_controller.rb
+13
-26
app/controllers/projects/cycle_analytics_controller.rb
app/controllers/projects/cycle_analytics_controller.rb
+2
-9
spec/requests/projects/cycle_analytics_events_spec.rb
spec/requests/projects/cycle_analytics_events_spec.rb
+14
-14
No files found.
app/controllers/concerns/cycle_analytics_params.rb
0 → 100644
View file @
192918cd
module
CycleAnalyticsParams
extend
ActiveSupport
::
Concern
def
start_date
(
params
)
params
[
:start_date
]
==
'30'
?
30
.
days
.
ago
:
90
.
days
.
ago
end
end
app/controllers/projects/cycle_analytics/events_controller.rb
View file @
192918cd
class
Projects::CycleAnalytics::EventsController
<
Projects
::
ApplicationController
class
Projects::CycleAnalytics::EventsController
<
Projects
::
ApplicationController
# TODO: fix authorization
include
CycleAnalyticsParams
# before_action :authorize_read_cycle_analytics!
# TODO: refactor +event_hash+
before_action
:authorize_read_cycle_analytics!
def
issue
def
issue
render_events
(
issues:
events
.
issue_events
)
render_events
(
events
.
issue_events
)
end
end
def
plan
def
plan
render_events
(
commits:
events
.
plan_events
)
render_events
(
events
.
plan_events
)
end
end
def
code
def
code
render_events
(
merge_requests:
events
.
code_events
)
render_events
(
events
.
code_events
)
end
end
def
test
def
test
@opts
=
{
from:
start_date
,
branch:
events_params
[
:branch_name
]
}
@opts
=
{
from:
start_date
(
events_params
)
,
branch:
events_params
[
:branch_name
]
}
render_events
(
builds:
events
.
test_events
)
render_events
(
events
.
test_events
)
end
end
def
review
def
review
render_events
(
merge_requests:
events
.
review_events
)
render_events
(
events
.
review_events
)
end
end
def
staging
def
staging
render_events
(
builds:
events
.
staging_events
)
render_events
(
events
.
staging_events
)
end
end
def
production
def
production
render_events
(
issues:
events
.
production_events
)
render_events
(
events
.
production_events
)
end
end
private
private
def
render_events
(
event
_hash
)
def
render_events
(
event
s
)
respond_to
do
|
format
|
respond_to
do
|
format
|
format
.
html
format
.
html
format
.
json
{
render
json:
event_hash
}
format
.
json
{
render
json:
{
items:
events
}
}
end
end
# TODO refactor this
def
start_date
case
events_params
[
:start_date
]
when
'30'
then
30
.
days
.
ago
when
'90'
then
90
.
days
.
ago
else
90
.
days
.
ago
end
end
end
end
...
@@ -60,7 +47,7 @@ class Projects::CycleAnalytics::EventsController < Projects::ApplicationControll
...
@@ -60,7 +47,7 @@ class Projects::CycleAnalytics::EventsController < Projects::ApplicationControll
end
end
def
options
def
options
@opts
||=
{
from:
start_date
}
@opts
||=
{
from:
start_date
(
events_params
)
}
end
end
def
events_params
def
events_params
...
...
app/controllers/projects/cycle_analytics_controller.rb
View file @
192918cd
class
Projects::CycleAnalyticsController
<
Projects
::
ApplicationController
class
Projects::CycleAnalyticsController
<
Projects
::
ApplicationController
include
ActionView
::
Helpers
::
DateHelper
include
ActionView
::
Helpers
::
DateHelper
include
ActionView
::
Helpers
::
TextHelper
include
ActionView
::
Helpers
::
TextHelper
include
CycleAnalyticsParams
before_action
:authorize_read_cycle_analytics!
before_action
:authorize_read_cycle_analytics!
def
show
def
show
@cycle_analytics
=
::
CycleAnalytics
.
new
(
@project
,
from:
parse_start_date
)
@cycle_analytics
=
::
CycleAnalytics
.
new
(
@project
,
from:
start_date
(
cycle_analytics_params
)
)
respond_to
do
|
format
|
respond_to
do
|
format
|
format
.
html
format
.
html
...
@@ -15,14 +16,6 @@ class Projects::CycleAnalyticsController < Projects::ApplicationController
...
@@ -15,14 +16,6 @@ class Projects::CycleAnalyticsController < Projects::ApplicationController
private
private
def
parse_start_date
case
cycle_analytics_params
[
:start_date
]
when
'30'
then
30
.
days
.
ago
when
'90'
then
90
.
days
.
ago
else
90
.
days
.
ago
end
end
def
cycle_analytics_params
def
cycle_analytics_params
return
{}
unless
params
[
:cycle_analytics
].
present?
return
{}
unless
params
[
:cycle_analytics
].
present?
...
...
spec/requests/projects/cycle_analytics_events_spec.rb
View file @
192918cd
...
@@ -17,17 +17,17 @@ describe 'cycle analytics events' do
...
@@ -17,17 +17,17 @@ describe 'cycle analytics events' do
it
'lists the issue events'
do
it
'lists the issue events'
do
get
namespace_project_cycle_analytics_issue_path
(
project
.
namespace
,
project
,
format: :json
)
get
namespace_project_cycle_analytics_issue_path
(
project
.
namespace
,
project
,
format: :json
)
expect
(
json_response
[
'i
ssue
s'
]).
not_to
be_empty
expect
(
json_response
[
'i
tem
s'
]).
not_to
be_empty
first_issue_iid
=
Issue
.
order
(
created_at: :desc
).
pluck
(
:iid
).
first
.
to_s
first_issue_iid
=
Issue
.
order
(
created_at: :desc
).
pluck
(
:iid
).
first
.
to_s
expect
(
json_response
[
'i
ssue
s'
].
first
[
'iid'
]).
to
eq
(
first_issue_iid
)
expect
(
json_response
[
'i
tem
s'
].
first
[
'iid'
]).
to
eq
(
first_issue_iid
)
end
end
it
'lists the plan events'
do
it
'lists the plan events'
do
get
namespace_project_cycle_analytics_plan_path
(
project
.
namespace
,
project
,
format: :json
)
get
namespace_project_cycle_analytics_plan_path
(
project
.
namespace
,
project
,
format: :json
)
expect
(
json_response
[
'
commit
s'
]).
not_to
be_empty
expect
(
json_response
[
'
item
s'
]).
not_to
be_empty
commits
=
[]
commits
=
[]
...
@@ -39,53 +39,53 @@ describe 'cycle analytics events' do
...
@@ -39,53 +39,53 @@ describe 'cycle analytics events' do
newest_sha
=
commits
.
sort_by
{
|
k
|
k
[
'date'
]
}.
first
[
:sha
][
0
...
8
]
newest_sha
=
commits
.
sort_by
{
|
k
|
k
[
'date'
]
}.
first
[
:sha
][
0
...
8
]
expect
(
json_response
[
'
commit
s'
].
first
[
'sha'
]).
to
eq
(
newest_sha
)
expect
(
json_response
[
'
item
s'
].
first
[
'sha'
]).
to
eq
(
newest_sha
)
end
end
it
'lists the code events'
do
it
'lists the code events'
do
get
namespace_project_cycle_analytics_code_path
(
project
.
namespace
,
project
,
format: :json
)
get
namespace_project_cycle_analytics_code_path
(
project
.
namespace
,
project
,
format: :json
)
expect
(
json_response
[
'
merge_request
s'
]).
not_to
be_empty
expect
(
json_response
[
'
item
s'
]).
not_to
be_empty
first_mr_iid
=
Issue
.
order
(
created_at: :desc
).
pluck
(
:iid
).
first
.
to_s
first_mr_iid
=
Issue
.
order
(
created_at: :desc
).
pluck
(
:iid
).
first
.
to_s
expect
(
json_response
[
'
merge_request
s'
].
first
[
'iid'
]).
to
eq
(
first_mr_iid
)
expect
(
json_response
[
'
item
s'
].
first
[
'iid'
]).
to
eq
(
first_mr_iid
)
end
end
it
'lists the test events'
do
it
'lists the test events'
do
get
namespace_project_cycle_analytics_test_path
(
project
.
namespace
,
project
,
format: :json
)
get
namespace_project_cycle_analytics_test_path
(
project
.
namespace
,
project
,
format: :json
)
expect
(
json_response
[
'
build
s'
]).
not_to
be_empty
expect
(
json_response
[
'
item
s'
]).
not_to
be_empty
expect
(
json_response
[
'
build
s'
].
first
[
'date'
]).
not_to
be_empty
expect
(
json_response
[
'
item
s'
].
first
[
'date'
]).
not_to
be_empty
end
end
it
'lists the review events'
do
it
'lists the review events'
do
get
namespace_project_cycle_analytics_review_path
(
project
.
namespace
,
project
,
format: :json
)
get
namespace_project_cycle_analytics_review_path
(
project
.
namespace
,
project
,
format: :json
)
expect
(
json_response
[
'
merge_request
s'
]).
not_to
be_empty
expect
(
json_response
[
'
item
s'
]).
not_to
be_empty
first_mr_iid
=
Issue
.
order
(
created_at: :desc
).
pluck
(
:iid
).
first
.
to_s
first_mr_iid
=
Issue
.
order
(
created_at: :desc
).
pluck
(
:iid
).
first
.
to_s
expect
(
json_response
[
'
merge_request
s'
].
first
[
'iid'
]).
to
eq
(
first_mr_iid
)
expect
(
json_response
[
'
item
s'
].
first
[
'iid'
]).
to
eq
(
first_mr_iid
)
end
end
it
'lists the staging events'
do
it
'lists the staging events'
do
get
namespace_project_cycle_analytics_staging_path
(
project
.
namespace
,
project
,
format: :json
)
get
namespace_project_cycle_analytics_staging_path
(
project
.
namespace
,
project
,
format: :json
)
expect
(
json_response
[
'
build
s'
]).
not_to
be_empty
expect
(
json_response
[
'
item
s'
]).
not_to
be_empty
expect
(
json_response
[
'
build
s'
].
first
[
'date'
]).
not_to
be_empty
expect
(
json_response
[
'
item
s'
].
first
[
'date'
]).
not_to
be_empty
end
end
it
'lists the production events'
do
it
'lists the production events'
do
get
namespace_project_cycle_analytics_production_path
(
project
.
namespace
,
project
,
format: :json
)
get
namespace_project_cycle_analytics_production_path
(
project
.
namespace
,
project
,
format: :json
)
expect
(
json_response
[
'i
ssue
s'
]).
not_to
be_empty
expect
(
json_response
[
'i
tem
s'
]).
not_to
be_empty
first_issue_iid
=
Issue
.
order
(
created_at: :desc
).
pluck
(
:iid
).
first
.
to_s
first_issue_iid
=
Issue
.
order
(
created_at: :desc
).
pluck
(
:iid
).
first
.
to_s
expect
(
json_response
[
'i
ssue
s'
].
first
[
'iid'
]).
to
eq
(
first_issue_iid
)
expect
(
json_response
[
'i
tem
s'
].
first
[
'iid'
]).
to
eq
(
first_issue_iid
)
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