BigW Consortium Gitlab

events_controller.rb 1.53 KB
Newer Older
1 2
module Projects
  module CycleAnalytics
3 4 5 6
    class EventsController < Projects::ApplicationController
      include CycleAnalyticsParams
    
      before_action :authorize_read_cycle_analytics!
7
      before_action :authorize_read_build!, only: [:test, :staging]
8 9 10
      before_action :authorize_read_issue!, only: [:issue, :production]
      before_action :authorize_read_merge_request!, only: [:code, :review]

11
      def issue
12
        render_events(cycle_analytics[:issue].events)
13 14 15
      end
    
      def plan
16
        render_events(cycle_analytics[:plan].events)
17 18 19
      end
    
      def code
20
        render_events(cycle_analytics[:code].events)
21 22 23
      end
    
      def test
James Lopez committed
24
        options(events_params)[:branch] = events_params[:branch_name]
25
    
26
        render_events(cycle_analytics[:test].events)
27 28 29
      end
    
      def review
30
        render_events(cycle_analytics[:review].events)
31 32 33
      end
    
      def staging
34
        render_events(cycle_analytics[:staging].events)
35 36 37
      end
    
      def production
38
        render_events(cycle_analytics[:production].events)
39 40 41
      end
    
      private
James Lopez committed
42 43

      def render_events(events)
44 45
        respond_to do |format|
          format.html
James Lopez committed
46
          format.json { render json: { events: events } }
47 48 49
        end
      end
    
James Lopez committed
50
      def cycle_analytics
51
        @cycle_analytics ||= ::CycleAnalytics.new(project, options(events_params))
52 53 54 55 56
      end
    
      def events_params
        return {} unless params[:events].present?
    
57
        params[:events].permit(:start_date, :branch_name)
58
      end
59 60
    end
  end
61
end