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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

139 lines
3.8 KiB
Ruby
Raw Permalink 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
2023-01-13 00:05:48 +05:30
system_hooks_tags = %w[system_hooks]
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
2023-01-13 00:05:48 +05:30
optional :token, type: String,
desc: "Secret token to validate received payloads; this isn't returned in the response"
optional :push_events, type: Boolean, desc: 'When true, the hook fires on push events'
optional :tag_push_events, type: Boolean, desc: 'When true, the hook fires on new tags being pushed'
optional :merge_requests_events, type: Boolean, desc: 'Trigger hook on merge requests 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'
2022-08-13 15:12:31 +05:30
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
2023-01-13 00:05:48 +05:30
desc 'List system hooks' do
detail 'Get a list of all system hooks'
2016-11-03 12:29:30 +05:30
success Entities::Hook
2023-01-13 00:05:48 +05:30
is_array true
tags system_hooks_tags
2016-11-03 12:29:30 +05:30
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
2023-01-13 00:05:48 +05:30
desc 'Get system hook' do
detail 'Get a system hook by its ID. Introduced in GitLab 14.9.'
2022-05-07 20:08:51 +05:30
success Entities::Hook
2023-01-13 00:05:48 +05:30
failure [
{ code: 404, message: 'Not found' }
]
tags system_hooks_tags
2022-05-07 20:08:51 +05:30
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
2023-01-13 00:05:48 +05:30
desc 'Add new system hook' do
detail 'Add a new system hook'
2016-11-03 12:29:30 +05:30
success Entities::Hook
2023-01-13 00:05:48 +05:30
failure [
{ code: 400, message: 'Validation error' },
{ code: 404, message: 'Not found' },
{ code: 422, message: 'Unprocessable entity' }
]
tags system_hooks_tags
2016-11-03 12:29:30 +05:30
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
2023-01-13 00:05:48 +05:30
desc 'Edit system hook' do
detail 'Edits a system hook'
2022-08-13 15:12:31 +05:30
success Entities::Hook
2023-01-13 00:05:48 +05:30
failure [
{ code: 400, message: 'Validation error' },
{ code: 404, message: 'Not found' },
{ code: 422, message: 'Unprocessable entity' }
]
tags system_hooks_tags
2022-08-13 15:12:31 +05:30
end
2016-11-03 12:29:30 +05:30
params do
2023-01-13 00:05:48 +05:30
requires :hook_id, type: Integer, desc: 'The ID of the system hook'
2022-08-13 15:12:31 +05:30
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
2023-01-13 00:05:48 +05:30
desc 'Delete system hook' do
detail 'Deletes a system hook'
2016-11-03 12:29:30 +05:30
success Entities::Hook
2023-01-13 00:05:48 +05:30
failure [
{ code: 404, message: 'Not found' }
]
tags system_hooks_tags
2016-11-03 12:29:30 +05:30
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