2014-09-02 18:07:02 +05:30
|
|
|
class Projects::HooksController < Projects::ApplicationController
|
|
|
|
# Authorize
|
2015-09-11 14:41:01 +05:30
|
|
|
before_action :authorize_admin_project!
|
2014-09-02 18:07:02 +05:30
|
|
|
|
|
|
|
respond_to :html
|
|
|
|
|
|
|
|
layout "project_settings"
|
|
|
|
|
|
|
|
def index
|
|
|
|
@hooks = @project.hooks
|
|
|
|
@hook = ProjectHook.new
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
|
|
|
@hook = @project.hooks.new(hook_params)
|
|
|
|
@hook.save
|
|
|
|
|
|
|
|
if @hook.valid?
|
2015-04-26 12:48:37 +05:30
|
|
|
redirect_to namespace_project_hooks_path(@project.namespace, @project)
|
2014-09-02 18:07:02 +05:30
|
|
|
else
|
|
|
|
@hooks = @project.hooks.select(&:persisted?)
|
|
|
|
render :index
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test
|
|
|
|
if !@project.empty_repo?
|
2015-12-23 02:04:40 +05:30
|
|
|
status, message = TestHookService.new.execute(hook, current_user)
|
2015-04-26 12:48:37 +05:30
|
|
|
|
2014-09-02 18:07:02 +05:30
|
|
|
if status
|
|
|
|
flash[:notice] = 'Hook successfully executed.'
|
|
|
|
else
|
2015-12-23 02:04:40 +05:30
|
|
|
flash[:alert] = "Hook execution failed: #{message}"
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
else
|
|
|
|
flash[:alert] = 'Hook execution failed. Ensure the project has commits.'
|
|
|
|
end
|
|
|
|
|
2015-10-24 18:46:33 +05:30
|
|
|
redirect_back_or_default(default: { action: 'index' })
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
hook.destroy
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
redirect_to namespace_project_hooks_path(@project.namespace, @project)
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def hook
|
|
|
|
@hook ||= @project.hooks.find(params[:id])
|
|
|
|
end
|
|
|
|
|
|
|
|
def hook_params
|
2015-09-25 12:07:36 +05:30
|
|
|
params.require(:hook).permit(:url, :push_events, :issues_events,
|
2015-12-23 02:04:40 +05:30
|
|
|
:merge_requests_events, :tag_push_events, :note_events,
|
|
|
|
:build_events, :enable_ssl_verification)
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
end
|