2013-06-23 16:47:22 +00:00
|
|
|
class Projects::HooksController < Projects::ApplicationController
|
2012-01-03 22:42:14 +00:00
|
|
|
# Authorize
|
2015-04-16 12:03:37 +00:00
|
|
|
before_action :authorize_admin_project!
|
2012-01-03 22:42:14 +00:00
|
|
|
|
|
|
|
respond_to :html
|
|
|
|
|
2013-06-19 19:44:57 +00:00
|
|
|
layout "project_settings"
|
|
|
|
|
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-01-18 21:40:16 +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-01-18 21:40:16 +00:00
|
|
|
redirect_to namespace_project_settings_integrations_path(@project.namespace, @project)
|
2012-01-03 22:42:14 +00:00
|
|
|
end
|
|
|
|
|
2012-01-08 10:20:24 +00:00
|
|
|
def test
|
2014-07-27 20:26:23 +00:00
|
|
|
if !@project.empty_repo?
|
2015-12-02 00:15:01 +00:00
|
|
|
status, message = TestHookService.new.execute(hook, current_user)
|
2014-12-04 13:07:01 +00:00
|
|
|
|
2016-05-03 11:40:59 +00:00
|
|
|
if status && status >= 200 && status < 400
|
2016-05-03 11:42:56 +00:00
|
|
|
flash[:notice] = "Hook executed successfully: HTTP #{status}"
|
2016-05-03 11:40:59 +00:00
|
|
|
elsif status
|
|
|
|
flash[:alert] = "Hook executed successfully but returned HTTP #{status} #{message}"
|
2014-07-29 09:49:46 +00:00
|
|
|
else
|
2015-12-02 00:15:01 +00:00
|
|
|
flash[:alert] = "Hook execution failed: #{message}"
|
2014-07-29 09:49:46 +00:00
|
|
|
end
|
2014-07-27 20:26:23 +00:00
|
|
|
else
|
|
|
|
flash[:alert] = 'Hook execution failed. Ensure the project has commits.'
|
|
|
|
end
|
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
|
|
|
|
2016-12-30 17:30:25 +00:00
|
|
|
redirect_to namespace_project_settings_integrations_path(@project.namespace, @project)
|
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
|
|
|
|
|
|
|
def hook_params
|
2016-04-30 08:34:31 +00:00
|
|
|
params.require(:hook).permit(
|
|
|
|
:build_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
|