2013-01-20 06:20:50 -05:00
|
|
|
class Admin::HooksController < Admin::ApplicationController
|
2017-04-27 06:08:57 -04:00
|
|
|
include HooksExecution
|
|
|
|
|
|
|
|
before_action :hook_logs, only: :edit
|
2017-04-20 04:31:37 -04:00
|
|
|
|
2012-07-12 15:10:34 -04:00
|
|
|
def index
|
|
|
|
@hooks = SystemHook.all
|
|
|
|
@hook = SystemHook.new
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
2014-06-26 11:51:11 -04:00
|
|
|
@hook = SystemHook.new(hook_params)
|
2012-07-12 15:10:34 -04:00
|
|
|
|
2012-07-15 08:29:06 -04:00
|
|
|
if @hook.save
|
|
|
|
redirect_to admin_hooks_path, notice: 'Hook was successfully created.'
|
|
|
|
else
|
|
|
|
@hooks = SystemHook.all
|
2012-09-16 07:44:54 -04:00
|
|
|
render :index
|
2012-07-12 15:10:34 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-04-20 04:31:37 -04:00
|
|
|
def edit
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
|
|
|
if hook.update_attributes(hook_params)
|
|
|
|
flash[:notice] = 'System hook was successfully updated.'
|
|
|
|
redirect_to admin_hooks_path
|
|
|
|
else
|
|
|
|
render 'edit'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-07-12 15:10:34 -04:00
|
|
|
def destroy
|
2017-04-20 04:31:37 -04:00
|
|
|
hook.destroy
|
2012-07-12 15:10:34 -04:00
|
|
|
|
2017-06-06 18:45:16 -04:00
|
|
|
redirect_to admin_hooks_path, status: 302
|
2012-07-12 15:10:34 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test
|
2017-04-27 06:08:57 -04:00
|
|
|
status, message = hook.execute(sample_hook_data, 'system_hooks')
|
|
|
|
|
|
|
|
set_hook_execution_notice(status, message)
|
2012-07-12 15:10:34 -04:00
|
|
|
|
2015-10-20 03:28:28 -04:00
|
|
|
redirect_back_or_default
|
2012-07-12 15:10:34 -04:00
|
|
|
end
|
2014-06-26 11:51:11 -04:00
|
|
|
|
2017-04-20 04:31:37 -04:00
|
|
|
private
|
|
|
|
|
|
|
|
def hook
|
|
|
|
@hook ||= SystemHook.find(params[:id])
|
|
|
|
end
|
|
|
|
|
2017-04-27 06:08:57 -04:00
|
|
|
def hook_logs
|
|
|
|
@hook_logs ||=
|
|
|
|
Kaminari.paginate_array(hook.web_hook_logs.order(created_at: :desc)).page(params[:page])
|
|
|
|
end
|
|
|
|
|
2014-06-26 11:51:11 -04:00
|
|
|
def hook_params
|
2016-04-30 04:34:31 -04:00
|
|
|
params.require(:hook).permit(
|
|
|
|
:enable_ssl_verification,
|
|
|
|
:push_events,
|
|
|
|
:tag_push_events,
|
2017-05-05 08:11:28 -04:00
|
|
|
:repository_update_events,
|
2016-04-30 04:34:31 -04:00
|
|
|
:token,
|
|
|
|
:url
|
|
|
|
)
|
2014-06-26 11:51:11 -04:00
|
|
|
end
|
2017-04-27 06:08:57 -04:00
|
|
|
|
|
|
|
def sample_hook_data
|
|
|
|
{
|
|
|
|
event_name: "project_create",
|
|
|
|
name: "Ruby",
|
|
|
|
path: "ruby",
|
|
|
|
project_id: 1,
|
|
|
|
owner_name: "Someone",
|
|
|
|
owner_email: "example@gitlabhq.com"
|
|
|
|
}
|
|
|
|
end
|
2012-07-12 15:10:34 -04:00
|
|
|
end
|