debian-mirror-gitlab/lib/api/system_hooks.rb

109 lines
2.8 KiB
Ruby
Raw Normal View History

2018-12-05 23:21:45 +05:30
# frozen_string_literal: true
2014-09-02 18:07:02 +05:30
module API
2021-01-03 14:25:43 +05:30
class SystemHooks < ::API::Base
2017-08-17 22:00:37 +05:30
include PaginationParams
2021-01-29 00:20:46 +05:30
feature_category :integrations
2015-04-26 12:48:37 +05:30
before do
2014-09-02 18:07:02 +05:30
authenticate!
authenticated_as_admin!
2015-04-26 12:48:37 +05:30
end
2014-09-02 18:07:02 +05:30
2022-08-13 15:12:31 +05:30
helpers ::API::Helpers::WebHooksHelpers
helpers do
def hook_scope
SystemHook
end
params :hook_parameters do
optional :token, type: String, desc: 'The token used to validate payloads'
optional :push_events, type: Boolean, desc: "Trigger hook on push events"
optional :tag_push_events, type: Boolean, desc: "Trigger hook on tag push events"
optional :merge_requests_events, type: Boolean, desc: "Trigger hook on tag push events"
optional :repository_update_events, type: Boolean, desc: "Trigger hook on repository update events"
optional :enable_ssl_verification, type: Boolean, desc: "Do SSL verification when triggering the hook"
use :url_variables
end
end
2014-09-02 18:07:02 +05:30
resource :hooks do
2022-08-13 15:12:31 +05:30
mount ::API::Hooks::UrlVariables
2016-11-03 12:29:30 +05:30
desc 'Get the list of system hooks' do
success Entities::Hook
end
2017-08-17 22:00:37 +05:30
params do
use :pagination
end
2014-09-02 18:07:02 +05:30
get do
2017-08-17 22:00:37 +05:30
present paginate(SystemHook.all), with: Entities::Hook
2014-09-02 18:07:02 +05:30
end
2022-05-07 20:08:51 +05:30
desc 'Get a hook' do
success Entities::Hook
end
params do
2022-08-13 15:12:31 +05:30
requires :hook_id, type: Integer, desc: 'The ID of the system hook'
2022-05-07 20:08:51 +05:30
end
2022-08-13 15:12:31 +05:30
get ":hook_id" do
present find_hook, with: Entities::Hook
2022-05-07 20:08:51 +05:30
end
2016-11-03 12:29:30 +05:30
desc 'Create a new system hook' do
success Entities::Hook
end
params do
2022-08-13 15:12:31 +05:30
use :requires_url
use :hook_parameters
2016-11-03 12:29:30 +05:30
end
2014-09-02 18:07:02 +05:30
post do
2022-08-13 15:12:31 +05:30
hook_params = create_hook_params
hook = SystemHook.new(hook_params)
2016-11-03 12:29:30 +05:30
2022-08-13 15:12:31 +05:30
save_hook(hook, Entities::Hook)
2014-09-02 18:07:02 +05:30
end
2022-08-13 15:12:31 +05:30
desc 'Update an existing system hook' do
success Entities::Hook
end
2016-11-03 12:29:30 +05:30
params do
2022-08-13 15:12:31 +05:30
requires :hook_id, type: Integer, desc: "The ID of the hook to update"
use :optional_url
use :hook_parameters
2016-11-03 12:29:30 +05:30
end
2022-08-13 15:12:31 +05:30
put ":hook_id" do
update_hook(entity: Entities::Hook)
end
mount ::API::Hooks::Test, with: {
data: {
2014-09-02 18:07:02 +05:30
event_name: "project_create",
name: "Ruby",
path: "ruby",
project_id: 1,
owner_name: "Someone",
owner_email: "example@gitlabhq.com"
2022-08-13 15:12:31 +05:30
},
kind: 'system_hooks'
}
2014-09-02 18:07:02 +05:30
2016-11-03 12:29:30 +05:30
desc 'Delete a hook' do
success Entities::Hook
end
params do
2022-08-13 15:12:31 +05:30
requires :hook_id, type: Integer, desc: 'The ID of the system hook'
2016-11-03 12:29:30 +05:30
end
2022-08-13 15:12:31 +05:30
delete ":hook_id" do
hook = find_hook
2016-11-03 12:29:30 +05:30
2021-01-03 14:25:43 +05:30
destroy_conditionally!(hook) do
WebHooks::DestroyService.new(current_user).execute(hook)
end
2014-09-02 18:07:02 +05:30
end
end
end
end