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