gitlab-org--gitlab-foss/app/controllers/projects/hooks_controller.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

82 lines
1.7 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
class Projects::HooksController < Projects::ApplicationController
include ::Integrations::HooksExecution
2012-01-03 17:42:14 -05:00
# Authorize
before_action :authorize_admin_project!
before_action :hook_logs, only: :edit
before_action -> { check_rate_limit!(:project_testing_hook, scope: [@project, current_user]) }, only: :test
2012-01-03 17:42:14 -05:00
respond_to :html
2013-06-19 15:44:57 -04:00
layout "project_settings"
feature_category :integrations
urgency :low, [:test]
2017-07-20 11:12:06 -04:00
def index
@hooks = @project.hooks.load
@hook = ProjectHook.new
2017-07-20 11:12:06 -04:00
end
2012-01-03 17:42:14 -05:00
def create
@hook = @project.hooks.new(hook_params)
2012-01-03 17:42:14 -05:00
@hook.save
unless @hook.valid?
@hooks = @project.hooks.select(&:persisted?)
flash[:alert] = @hook.errors.full_messages.join.html_safe
2012-01-03 17:42:14 -05:00
end
redirect_to action: :index
2012-01-03 17:42:14 -05:00
end
2017-04-20 04:31:37 -04:00
def edit
redirect_to(action: :index) unless hook
2017-04-20 04:31:37 -04:00
end
def update
2018-07-02 06:43:06 -04:00
if hook.update(hook_params)
flash[:notice] = _('Hook was successfully updated.')
redirect_to action: :index
2017-04-20 04:31:37 -04:00
else
render 'edit'
end
end
def test
2017-07-20 11:12:06 -04:00
result = TestHooks::ProjectService.new(hook, current_user, params[:trigger]).execute
2017-07-20 11:12:06 -04:00
set_hook_execution_notice(result)
redirect_back_or_default(default: { action: :index })
end
2012-01-03 17:42:14 -05:00
def destroy
destroy_hook(hook)
2012-01-03 17:42:14 -05:00
redirect_to action: :index, status: :found
2012-01-03 17:42:14 -05:00
end
private
def hook
@hook ||= @project.hooks.find(params[:id])
end
def hook_logs
@hook_logs ||= hook.web_hook_logs.recent.page(params[:page])
end
def hook_params
params.require(:hook).permit(
:enable_ssl_verification,
:token,
:url,
:push_events_branch_filter,
*ProjectHook.triggers.values
)
end
2012-01-03 17:42:14 -05:00
end