summaryrefslogtreecommitdiff
path: root/app/controllers/projects/ci_web_hooks_controller.rb
blob: a2d470d4a6964143202f620acbf49d8bdb740f52 (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
class Projects::CiWebHooksController < Projects::ApplicationController
  before_action :ci_project
  before_action :authorize_admin_project!

  layout "project_settings"

  def index
    @web_hooks = @ci_project.web_hooks
    @web_hook = Ci::WebHook.new
  end

  def create
    @web_hook = @ci_project.web_hooks.new(web_hook_params)
    @web_hook.save

    if @web_hook.valid?
      redirect_to namespace_project_ci_web_hooks_path(@project.namespace, @project)
    else
      @web_hooks = @ci_project.web_hooks.select(&:persisted?)
      render :index
    end
  end

  def test
    Ci::TestHookService.new.execute(hook, current_user)

    redirect_back_or_default(default: { action: 'index' })
  end

  def destroy
    hook.destroy

    redirect_to namespace_project_ci_web_hooks_path(@project.namespace, @project)
  end

  private

  def hook
    @web_hook ||= @ci_project.web_hooks.find(params[:id])
  end

  def web_hook_params
    params.require(:web_hook).permit(:url)
  end
end