2018-12-05 23:21:45 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2014-09-02 18:07:02 +05:30
|
|
|
class Projects::HooksController < Projects::ApplicationController
|
2017-09-10 17:25:29 +05:30
|
|
|
include HooksExecution
|
|
|
|
|
2014-09-02 18:07:02 +05:30
|
|
|
# Authorize
|
2015-09-11 14:41:01 +05:30
|
|
|
before_action :authorize_admin_project!
|
2017-09-10 17:25:29 +05:30
|
|
|
before_action :hook_logs, only: :edit
|
2020-09-03 11:15:55 +05:30
|
|
|
before_action -> { create_rate_limit(:project_testing_hook, @project) }, only: :test
|
2014-09-02 18:07:02 +05:30
|
|
|
|
|
|
|
respond_to :html
|
|
|
|
|
|
|
|
layout "project_settings"
|
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
feature_category :integrations
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
def index
|
2020-04-08 14:13:33 +05:30
|
|
|
@hooks = @project.hooks
|
|
|
|
@hook = ProjectHook.new
|
2017-09-10 17:25:29 +05:30
|
|
|
end
|
|
|
|
|
2014-09-02 18:07:02 +05:30
|
|
|
def create
|
|
|
|
@hook = @project.hooks.new(hook_params)
|
|
|
|
@hook.save
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
unless @hook.valid?
|
2014-09-02 18:07:02 +05:30
|
|
|
@hooks = @project.hooks.select(&:persisted?)
|
2017-08-17 22:00:37 +05:30
|
|
|
flash[:alert] = @hook.errors.full_messages.join.html_safe
|
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
redirect_to action: :index
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
2018-11-18 11:00:15 +05:30
|
|
|
if hook.update(hook_params)
|
2019-05-18 00:54:41 +05:30
|
|
|
flash[:notice] = _('Hook was successfully updated.')
|
2020-04-08 14:13:33 +05:30
|
|
|
redirect_to action: :index
|
2017-08-17 22:00:37 +05:30
|
|
|
else
|
|
|
|
render 'edit'
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test
|
2017-09-10 17:25:29 +05:30
|
|
|
result = TestHooks::ProjectService.new(hook, current_user, params[:trigger]).execute
|
|
|
|
|
|
|
|
set_hook_execution_notice(result)
|
2014-09-02 18:07:02 +05:30
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
redirect_back_or_default(default: { action: :index })
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
2021-01-03 14:25:43 +05:30
|
|
|
destroy_hook(hook)
|
2014-09-02 18:07:02 +05:30
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
redirect_to action: :index, status: :found
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def hook
|
|
|
|
@hook ||= @project.hooks.find(params[:id])
|
|
|
|
end
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
def hook_logs
|
2018-11-08 19:23:39 +05:30
|
|
|
@hook_logs ||= hook.web_hook_logs.recent.page(params[:page])
|
2017-09-10 17:25:29 +05:30
|
|
|
end
|
|
|
|
|
2014-09-02 18:07:02 +05:30
|
|
|
def hook_params
|
2016-06-02 11:05:42 +05:30
|
|
|
params.require(:hook).permit(
|
|
|
|
:enable_ssl_verification,
|
|
|
|
:token,
|
2016-06-16 23:09:34 +05:30
|
|
|
:url,
|
2018-11-20 20:47:30 +05:30
|
|
|
:push_events_branch_filter,
|
2018-03-17 18:26:18 +05:30
|
|
|
*ProjectHook.triggers.values
|
2016-06-02 11:05:42 +05:30
|
|
|
)
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
end
|