Remove system hooks TEST endpoint
What
Follow-up from: https://gitlab.com/gitlab-org/gitlab/-/issues/376994
While adding system_hooks
to the OpenApiV2 documentation, we came across the TEST
endpoint where the response was returning a dummy data:
data: {
event_name: "project_create",
name: "Ruby",
path: "ruby",
project_id: 1,
owner_name: "Someone",
owner_email: "example@gitlabhq.com"
}
We have to ensure that endpoint works as expected.
#1
Proposal We should remove the endpoint and associated documentation because no one is using that.
- https://gitlab.com/gitlab-org/gitlab/-/blob/fe958633ff2edba506ff601166d7955e544e9c68/lib/api/system_hooks.rb#L106-L117
- https://gitlab.com/gitlab-org/gitlab/-/blob/fe958633ff2edba506ff601166d7955e544e9c68/doc/api/system_hooks.md#L127-L155
#2
(Discarded)
Proposal We should change the endpoint to match the current documentation test-system-hook. Example:
params :trigger_params do
requires :trigger, type: String,
values: %w[push_events tag_push_events merge_requests_events repository_update_events],
desc: 'Set of events to be triggered against the system hook'
end
desc 'Test system hook' do
detail 'Tests a system hook'
success code: 200, message: 'OK'
failure [
{ code: 400, message: 'Validation error' },
{ code: 404, message: 'Not found' },
{ code: 422, message: 'Unprocessable entity' }
]
tags system_hooks_tags
end
params do
requires :hook_id, type: Integer, desc: 'The ID of the system hook'
use :trigger_params
end
post ":hook_id/test" do
hook = find_hook
TestHooks::SystemService.new(hook, current_user, params[:trigger]).execute
end
The API::Hooks::Test
isn't used anywhere else, so if we're not using it anymore, we should remove it. We should update following specs:
spec/requests/api/system_hooks_spec.rb
spec/support/shared_examples/requests/api/hooks_shared_examples.rb
Examples:
describe "POST #{prefix}/:hook_id/test" do
it 'tests the hook' do
expect(WebHookService)
.to receive(:new).with(hook, anything, String, force: false)
.and_return(instance_double(WebHookService, execute: nil))
expect(test_service)
.to receive(:new).with(hook, user, String)
.and_return(instance_double(test_service, execute: nil))
post api(hook_uri, user)
post api(test_hook_uri, user), params: test_params
expect(response).to have_gitlab_http_status(:created)
end
end
def test_hook_uri(hook_id = hook.id)
"/hooks/#{hook_id}/test"
end
let(:test_params) do
{ trigger: 'push_events' }
end
let(:test_service) do
TestHooks::SystemService
end
Edited by Arturo Herrero