2013-06-23 16:47:22 +00:00
|
|
|
class Projects::HooksController < Projects::ApplicationController
|
2017-04-27 10:08:57 +00:00
|
|
|
include HooksExecution
|
|
|
|
|
2012-01-03 22:42:14 +00:00
|
|
|
# Authorize
|
2015-04-16 12:03:37 +00:00
|
|
|
before_action :authorize_admin_project!
|
2017-04-27 10:08:57 +00:00
|
|
|
before_action :hook_logs, only: :edit
|
2012-01-03 22:42:14 +00:00
|
|
|
|
|
|
|
respond_to :html
|
|
|
|
|
2013-06-19 19:44:57 +00:00
|
|
|
layout "project_settings"
|
|
|
|
|
2017-07-20 15:12:06 +00:00
|
|
|
def index
|
|
|
|
redirect_to project_settings_integrations_path(@project)
|
|
|
|
end
|
|
|
|
|
2012-01-03 22:42:14 +00:00
|
|
|
def create
|
2014-06-26 15:45:33 +00:00
|
|
|
@hook = @project.hooks.new(hook_params)
|
2012-01-03 22:42:14 +00:00
|
|
|
@hook.save
|
|
|
|
|
2017-04-10 10:05:29 +00:00
|
|
|
unless @hook.valid?
|
2014-04-06 15:42:24 +00:00
|
|
|
@hooks = @project.hooks.select(&:persisted?)
|
2017-01-18 18:09:32 +00:00
|
|
|
flash[:alert] = @hook.errors.full_messages.join.html_safe
|
2012-01-03 22:42:14 +00:00
|
|
|
end
|
2017-06-29 17:06:35 +00:00
|
|
|
redirect_to project_settings_integrations_path(@project)
|
2012-01-03 22:42:14 +00:00
|
|
|
end
|
|
|
|
|
2017-04-20 08:31:37 +00:00
|
|
|
def edit
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
|
|
|
if hook.update_attributes(hook_params)
|
|
|
|
flash[:notice] = 'Hook was successfully updated.'
|
2017-06-29 17:06:35 +00:00
|
|
|
redirect_to project_settings_integrations_path(@project)
|
2017-04-20 08:31:37 +00:00
|
|
|
else
|
|
|
|
render 'edit'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-01-08 10:20:24 +00:00
|
|
|
def test
|
2017-07-20 15:12:06 +00:00
|
|
|
result = TestHooks::ProjectService.new(hook, current_user, params[:trigger]).execute
|
2014-12-04 13:07:01 +00:00
|
|
|
|
2017-07-20 15:12:06 +00:00
|
|
|
set_hook_execution_notice(result)
|
2012-01-08 10:20:24 +00:00
|
|
|
|
2015-10-20 07:28:28 +00:00
|
|
|
redirect_back_or_default(default: { action: 'index' })
|
2012-01-08 10:20:24 +00:00
|
|
|
end
|
|
|
|
|
2012-01-03 22:42:14 +00:00
|
|
|
def destroy
|
2014-01-15 12:38:50 +00:00
|
|
|
hook.destroy
|
2012-01-03 22:42:14 +00:00
|
|
|
|
2017-06-29 17:06:35 +00:00
|
|
|
redirect_to project_settings_integrations_path(@project), status: 302
|
2012-01-03 22:42:14 +00:00
|
|
|
end
|
2014-01-15 12:38:50 +00:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def hook
|
|
|
|
@hook ||= @project.hooks.find(params[:id])
|
|
|
|
end
|
2014-06-26 15:45:33 +00:00
|
|
|
|
2017-04-27 10:08:57 +00:00
|
|
|
def hook_logs
|
|
|
|
@hook_logs ||=
|
|
|
|
Kaminari.paginate_array(hook.web_hook_logs.order(created_at: :desc)).page(params[:page])
|
|
|
|
end
|
|
|
|
|
2014-06-26 15:45:33 +00:00
|
|
|
def hook_params
|
2016-04-30 08:34:31 +00:00
|
|
|
params.require(:hook).permit(
|
2017-04-10 10:05:29 +00:00
|
|
|
:job_events,
|
2016-08-02 10:06:31 +00:00
|
|
|
:pipeline_events,
|
2016-04-30 08:34:31 +00:00
|
|
|
:enable_ssl_verification,
|
|
|
|
:issues_events,
|
2016-08-30 20:56:26 +00:00
|
|
|
:confidential_issues_events,
|
2016-04-30 08:34:31 +00:00
|
|
|
:merge_requests_events,
|
|
|
|
:note_events,
|
|
|
|
:push_events,
|
|
|
|
:tag_push_events,
|
|
|
|
:token,
|
2016-05-13 03:25:33 +00:00
|
|
|
:url,
|
|
|
|
:wiki_page_events
|
2016-04-30 08:34:31 +00:00
|
|
|
)
|
2014-06-26 15:45:33 +00:00
|
|
|
end
|
2012-01-03 22:42:14 +00:00
|
|
|
end
|