debian-mirror-gitlab/app/controllers/projects/cycle_analytics/events_controller.rb

62 lines
1.5 KiB
Ruby
Raw Normal View History

2017-08-17 22:00:37 +05:30
module Projects
module CycleAnalytics
class EventsController < Projects::ApplicationController
include CycleAnalyticsParams
2018-03-17 18:26:18 +05:30
2017-08-17 22:00:37 +05:30
before_action :authorize_read_cycle_analytics!
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]
def issue
render_events(cycle_analytics[:issue].events)
end
2018-03-17 18:26:18 +05:30
2017-08-17 22:00:37 +05:30
def plan
render_events(cycle_analytics[:plan].events)
end
2018-03-17 18:26:18 +05:30
2017-08-17 22:00:37 +05:30
def code
render_events(cycle_analytics[:code].events)
end
2018-03-17 18:26:18 +05:30
2017-08-17 22:00:37 +05:30
def test
options(events_params)[:branch] = events_params[:branch_name]
2018-03-17 18:26:18 +05:30
2017-08-17 22:00:37 +05:30
render_events(cycle_analytics[:test].events)
end
2018-03-17 18:26:18 +05:30
2017-08-17 22:00:37 +05:30
def review
render_events(cycle_analytics[:review].events)
end
2018-03-17 18:26:18 +05:30
2017-08-17 22:00:37 +05:30
def staging
render_events(cycle_analytics[:staging].events)
end
2018-03-17 18:26:18 +05:30
2017-08-17 22:00:37 +05:30
def production
render_events(cycle_analytics[:production].events)
end
2018-03-17 18:26:18 +05:30
2017-08-17 22:00:37 +05:30
private
def render_events(events)
respond_to do |format|
format.html
format.json { render json: { events: events } }
end
end
2018-03-17 18:26:18 +05:30
2017-08-17 22:00:37 +05:30
def cycle_analytics
@cycle_analytics ||= ::CycleAnalytics.new(project, options(events_params))
end
2018-03-17 18:26:18 +05:30
2017-08-17 22:00:37 +05:30
def events_params
return {} unless params[:events].present?
2018-03-17 18:26:18 +05:30
2017-08-17 22:00:37 +05:30
params[:events].permit(:start_date, :branch_name)
end
end
end
end