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.

110 lines
3.7 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
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
requires :id, type: String, desc: 'The ID of a project'
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
2017-08-17 22:00:37 +05:30
desc 'Get project hooks' do
success Entities::ProjectHook
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
2017-08-17 22:00:37 +05:30
desc 'Get a project hook' do
success Entities::ProjectHook
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
2017-08-17 22:00:37 +05:30
desc 'Add hook to project' do
success Entities::ProjectHook
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
2022-08-13 15:12:31 +05:30
desc 'Update an existing hook' do
2017-08-17 22:00:37 +05:30
success Entities::ProjectHook
end
params do
requires :hook_id, type: Integer, desc: "The ID of the hook to update"
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
2017-08-17 22:00:37 +05:30
desc 'Deletes project hook' do
success Entities::ProjectHook
end
params do
requires :hook_id, type: Integer, desc: 'The ID of the hook to delete'
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