2016-11-16 03:58:23 -05:00
|
|
|
module Projects
|
|
|
|
module CycleAnalytics
|
2016-11-16 06:01:10 -05:00
|
|
|
class EventsController < Projects::ApplicationController
|
|
|
|
include CycleAnalyticsParams
|
2017-08-15 13:44:37 -04:00
|
|
|
|
2016-11-16 06:01:10 -05:00
|
|
|
before_action :authorize_read_cycle_analytics!
|
2016-11-18 07:00:38 -05:00
|
|
|
before_action :authorize_read_build!, only: [:test, :staging]
|
2016-11-18 06:05:29 -05:00
|
|
|
before_action :authorize_read_issue!, only: [:issue, :production]
|
|
|
|
before_action :authorize_read_merge_request!, only: [:code, :review]
|
|
|
|
|
2016-11-16 06:01:10 -05:00
|
|
|
def issue
|
2016-12-01 05:21:24 -05:00
|
|
|
render_events(cycle_analytics[:issue].events)
|
2016-11-16 06:01:10 -05:00
|
|
|
end
|
2017-08-15 13:44:37 -04:00
|
|
|
|
2016-11-16 06:01:10 -05:00
|
|
|
def plan
|
2016-12-01 05:21:24 -05:00
|
|
|
render_events(cycle_analytics[:plan].events)
|
2016-11-16 06:01:10 -05:00
|
|
|
end
|
2017-08-15 13:44:37 -04:00
|
|
|
|
2016-11-16 06:01:10 -05:00
|
|
|
def code
|
2016-12-01 05:21:24 -05:00
|
|
|
render_events(cycle_analytics[:code].events)
|
2016-11-16 06:01:10 -05:00
|
|
|
end
|
2017-08-15 13:44:37 -04:00
|
|
|
|
2016-11-16 06:01:10 -05:00
|
|
|
def test
|
2016-11-23 05:28:28 -05:00
|
|
|
options(events_params)[:branch] = events_params[:branch_name]
|
2017-08-15 13:44:37 -04:00
|
|
|
|
2016-12-01 05:21:24 -05:00
|
|
|
render_events(cycle_analytics[:test].events)
|
2016-11-16 06:01:10 -05:00
|
|
|
end
|
2017-08-15 13:44:37 -04:00
|
|
|
|
2016-11-16 06:01:10 -05:00
|
|
|
def review
|
2016-12-01 05:21:24 -05:00
|
|
|
render_events(cycle_analytics[:review].events)
|
2016-11-16 06:01:10 -05:00
|
|
|
end
|
2017-08-15 13:44:37 -04:00
|
|
|
|
2016-11-16 06:01:10 -05:00
|
|
|
def staging
|
2016-12-01 05:21:24 -05:00
|
|
|
render_events(cycle_analytics[:staging].events)
|
2016-11-16 06:01:10 -05:00
|
|
|
end
|
2017-08-15 13:44:37 -04:00
|
|
|
|
2016-11-16 06:01:10 -05:00
|
|
|
def production
|
2016-12-01 05:21:24 -05:00
|
|
|
render_events(cycle_analytics[:production].events)
|
2016-11-16 06:01:10 -05:00
|
|
|
end
|
2017-08-15 13:44:37 -04:00
|
|
|
|
2016-11-16 06:01:10 -05:00
|
|
|
private
|
2016-11-23 05:28:28 -05:00
|
|
|
|
|
|
|
def render_events(events)
|
2016-11-16 06:01:10 -05:00
|
|
|
respond_to do |format|
|
|
|
|
format.html
|
2016-11-23 05:28:28 -05:00
|
|
|
format.json { render json: { events: events } }
|
2016-11-16 06:01:10 -05:00
|
|
|
end
|
|
|
|
end
|
2017-08-15 13:44:37 -04:00
|
|
|
|
2016-11-23 05:28:28 -05:00
|
|
|
def cycle_analytics
|
2016-12-01 06:44:35 -05:00
|
|
|
@cycle_analytics ||= ::CycleAnalytics.new(project, options(events_params))
|
2016-11-16 06:01:10 -05:00
|
|
|
end
|
2017-08-15 13:44:37 -04:00
|
|
|
|
2016-11-16 06:01:10 -05:00
|
|
|
def events_params
|
|
|
|
return {} unless params[:events].present?
|
2017-08-15 13:44:37 -04:00
|
|
|
|
2016-12-01 05:21:24 -05:00
|
|
|
params[:events].permit(:start_date, :branch_name)
|
2016-11-16 06:01:10 -05:00
|
|
|
end
|
2016-10-24 10:24:56 -04:00
|
|
|
end
|
|
|
|
end
|
2016-10-27 12:52:42 -04:00
|
|
|
end
|