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

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

139 lines
4.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 ProjectHooks < ::API::Base
2017-08-17 22:00:37 +05:30
include PaginationParams
2023-01-13 00:05:48 +05:30
project_hooks_tags = %w[project_hooks]
2014-09-02 18:07:02 +05:30
before { authenticate! }
before { authorize_admin_project }
2021-01-29 00:20:46 +05:30
feature_category :integrations
2022-08-13 15:12:31 +05:30
helpers ::API::Helpers::WebHooksHelpers
2017-08-17 22:00:37 +05:30
helpers do
2022-08-13 15:12:31 +05:30
def hook_scope
user_project.hooks
end
params :common_hook_parameters do
2017-08-17 22:00:37 +05:30
optional :push_events, type: Boolean, desc: "Trigger hook on push events"
optional :issues_events, type: Boolean, desc: "Trigger hook on issues events"
2018-03-27 19:54:05 +05:30
optional :confidential_issues_events, type: Boolean, desc: "Trigger hook on confidential issues events"
2017-08-17 22:00:37 +05:30
optional :merge_requests_events, type: Boolean, desc: "Trigger hook on merge request events"
optional :tag_push_events, type: Boolean, desc: "Trigger hook on tag push events"
2022-08-13 15:12:31 +05:30
optional :note_events, type: Boolean, desc: "Trigger hook on note (comment) events"
optional :confidential_note_events, type: Boolean, desc: "Trigger hook on confidential note (comment) events"
2017-08-17 22:00:37 +05:30
optional :job_events, type: Boolean, desc: "Trigger hook on job events"
optional :pipeline_events, type: Boolean, desc: "Trigger hook on pipeline events"
optional :wiki_page_events, type: Boolean, desc: "Trigger hook on wiki events"
2020-10-24 23:57:45 +05:30
optional :deployment_events, type: Boolean, desc: "Trigger hook on deployment events"
2021-01-29 00:20:46 +05:30
optional :releases_events, type: Boolean, desc: "Trigger hook on release events"
2017-08-17 22:00:37 +05:30
optional :enable_ssl_verification, type: Boolean, desc: "Do SSL verification when triggering the hook"
optional :token, type: String, desc: "Secret token to validate received payloads; this will not be returned in the response"
2018-11-20 20:47:30 +05:30
optional :push_events_branch_filter, type: String, desc: "Trigger hook on specified branch only"
2022-08-13 15:12:31 +05:30
use :url_variables
2017-08-17 22:00:37 +05:30
end
end
params do
2023-01-13 00:05:48 +05:30
requires :id, types: [String, Integer], desc: 'The ID or URL-encoded path of the project'
2017-08-17 22:00:37 +05:30
end
2019-02-15 15:39:39 +05:30
resource :projects, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do
2022-08-13 15:12:31 +05:30
namespace ':id/hooks' do
mount ::API::Hooks::UrlVariables
end
2023-01-13 00:05:48 +05:30
desc 'List project hooks' do
detail 'Get a list of project hooks'
2017-08-17 22:00:37 +05:30
success Entities::ProjectHook
2023-01-13 00:05:48 +05:30
is_array true
tags project_hooks_tags
2017-08-17 22:00:37 +05:30
end
params do
use :pagination
end
2014-09-02 18:07:02 +05:30
get ":id/hooks" do
2017-08-17 22:00:37 +05:30
present paginate(user_project.hooks), with: Entities::ProjectHook
2014-09-02 18:07:02 +05:30
end
2023-01-13 00:05:48 +05:30
desc 'Get project hook' do
detail 'Get a specific hook for a project'
2017-08-17 22:00:37 +05:30
success Entities::ProjectHook
2023-01-13 00:05:48 +05:30
failure [
{ code: 404, message: 'Not found' }
]
tags project_hooks_tags
2017-08-17 22:00:37 +05:30
end
params do
requires :hook_id, type: Integer, desc: 'The ID of a project hook'
end
2014-09-02 18:07:02 +05:30
get ":id/hooks/:hook_id" do
2017-08-17 22:00:37 +05:30
hook = user_project.hooks.find(params[:hook_id])
present hook, with: Entities::ProjectHook
2014-09-02 18:07:02 +05:30
end
2023-01-13 00:05:48 +05:30
desc 'Add project hook' do
detail 'Adds a hook to a specified project'
2017-08-17 22:00:37 +05:30
success Entities::ProjectHook
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 project_hooks_tags
2017-08-17 22:00:37 +05:30
end
params do
2022-08-13 15:12:31 +05:30
use :requires_url
use :common_hook_parameters
2017-08-17 22:00:37 +05:30
end
2014-09-02 18:07:02 +05:30
post ":id/hooks" do
2022-08-13 15:12:31 +05:30
hook_params = create_hook_params
2017-08-17 22:00:37 +05:30
hook = user_project.hooks.new(hook_params)
2014-09-02 18:07:02 +05:30
2022-08-13 15:12:31 +05:30
save_hook(hook, Entities::ProjectHook)
2014-09-02 18:07:02 +05:30
end
2023-01-13 00:05:48 +05:30
desc 'Edit project hook' do
detail 'Edits a hook for a specified project.'
2017-08-17 22:00:37 +05:30
success Entities::ProjectHook
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 project_hooks_tags
2017-08-17 22:00:37 +05:30
end
params do
2023-01-13 00:05:48 +05:30
requires :hook_id, type: Integer, desc: 'The ID of the project hook'
2022-08-13 15:12:31 +05:30
use :optional_url
use :common_hook_parameters
2017-08-17 22:00:37 +05:30
end
2014-09-02 18:07:02 +05:30
put ":id/hooks/:hook_id" do
2022-08-13 15:12:31 +05:30
update_hook(entity: Entities::ProjectHook)
2014-09-02 18:07:02 +05:30
end
2023-01-13 00:05:48 +05:30
desc 'Delete a project hook' do
detail 'Removes a hook from a project. This is an idempotent method and can be called multiple times. Either the hook is available or not.'
2017-08-17 22:00:37 +05:30
success Entities::ProjectHook
2023-01-13 00:05:48 +05:30
failure [
{ code: 404, message: 'Not found' }
]
tags project_hooks_tags
2017-08-17 22:00:37 +05:30
end
params do
2023-01-13 00:05:48 +05:30
requires :hook_id, type: Integer, desc: 'The ID of the project hook'
2017-08-17 22:00:37 +05:30
end
2014-09-02 18:07:02 +05:30
delete ":id/hooks/:hook_id" do
2022-08-13 15:12:31 +05:30
hook = find_hook
2014-09-02 18:07:02 +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