summaryrefslogtreecommitdiff
path: root/app/controllers/ci/services_controller.rb
blob: 52c96a34ce88499ff1b2897dfcd561b9f96992fa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
module Ci
  class ServicesController < Ci::ApplicationController
    before_action :authenticate_user!
    before_action :project
    before_action :authorize_access_project!
    before_action :authorize_manage_project!
    before_action :service, only: [:edit, :update, :test]

    respond_to :html

    layout 'ci/project'

    def index
      @project.build_missing_services
      @services = @project.services.reload
    end

    def edit
    end

    def update
      if @service.update_attributes(service_params)
        redirect_to edit_ci_project_service_path(@project, @service.to_param)
      else
        render 'edit'
      end
    end

    def test
      last_build = @project.builds.last

      if @service.execute(last_build)
        message = { notice: 'We successfully tested the service' }
      else
        message = { alert: 'We tried to test the service but error occurred' }
      end

      redirect_to :back, message
    end

    private

    def project
      @project = Ci::Project.find(params[:project_id])
    end

    def service
      @service ||= @project.services.find { |service| service.to_param == params[:id] }
    end

    def service_params
      params.require(:service).permit(
        :type, :active, :webhook, :notify_only_broken_builds,
        :email_recipients, :email_only_broken_builds, :email_add_pusher,
        :hipchat_token, :hipchat_room, :hipchat_server
      )
    end
  end
end