debian-mirror-gitlab/app/controllers/projects/hooks_controller.rb

81 lines
1.7 KiB
Ruby
Raw Normal View History

2014-09-02 18:07:02 +05:30
class Projects::HooksController < Projects::ApplicationController
2017-09-10 17:25:29 +05:30
include HooksExecution
2014-09-02 18:07:02 +05:30
# Authorize
2015-09-11 14:41:01 +05:30
before_action :authorize_admin_project!
2017-09-10 17:25:29 +05:30
before_action :hook_logs, only: :edit
2014-09-02 18:07:02 +05:30
respond_to :html
layout "project_settings"
2017-09-10 17:25:29 +05:30
def index
redirect_to project_settings_integrations_path(@project)
end
2014-09-02 18:07:02 +05:30
def create
@hook = @project.hooks.new(hook_params)
@hook.save
2017-08-17 22:00:37 +05:30
unless @hook.valid?
2014-09-02 18:07:02 +05:30
@hooks = @project.hooks.select(&:persisted?)
2017-08-17 22:00:37 +05:30
flash[:alert] = @hook.errors.full_messages.join.html_safe
end
2017-09-10 17:25:29 +05:30
redirect_to project_settings_integrations_path(@project)
2017-08-17 22:00:37 +05:30
end
def edit
end
def update
if hook.update_attributes(hook_params)
flash[:notice] = 'Hook was successfully updated.'
2017-09-10 17:25:29 +05:30
redirect_to project_settings_integrations_path(@project)
2017-08-17 22:00:37 +05:30
else
render 'edit'
2014-09-02 18:07:02 +05:30
end
end
def test
2017-09-10 17:25:29 +05:30
result = TestHooks::ProjectService.new(hook, current_user, params[:trigger]).execute
set_hook_execution_notice(result)
2014-09-02 18:07:02 +05:30
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
2017-09-10 17:25:29 +05:30
redirect_to project_settings_integrations_path(@project), status: 302
2014-09-02 18:07:02 +05:30
end
private
def hook
@hook ||= @project.hooks.find(params[:id])
end
2017-09-10 17:25:29 +05:30
def hook_logs
@hook_logs ||=
Kaminari.paginate_array(hook.web_hook_logs.order(created_at: :desc)).page(params[:page])
end
2014-09-02 18:07:02 +05:30
def hook_params
2016-06-02 11:05:42 +05:30
params.require(:hook).permit(
2017-08-17 22:00:37 +05:30
:job_events,
2016-09-13 17:45:13 +05:30
:pipeline_events,
2016-06-02 11:05:42 +05:30
:enable_ssl_verification,
:issues_events,
2016-09-29 09:46:39 +05:30
:confidential_issues_events,
2016-06-02 11:05:42 +05:30
:merge_requests_events,
:note_events,
:push_events,
:tag_push_events,
:token,
:url,
:wiki_page_events
2016-06-02 11:05:42 +05:30
)
2014-09-02 18:07:02 +05:30
end
end