File: resend_hook.rb

package info (click to toggle)
gitlab 17.6.5-19
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 629,368 kB
  • sloc: ruby: 1,915,304; javascript: 557,307; sql: 60,639; xml: 6,509; sh: 4,567; makefile: 1,239; python: 406
file content (34 lines) | stat: -rw-r--r-- 1,119 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# frozen_string_literal: true

module API
  module Hooks
    # rubocop: disable API/Base -- re-usable module
    class ResendHook < ::Grape::API
      desc 'Resend a webhook event' do
        detail 'Resend a webhook event'
        success code: 201
        failure [
          { code: 422, message: 'Unprocessable entity' },
          { code: 404, message: 'Not found' },
          { code: 429, message: 'Too many requests' }
        ]
      end
      post ":hook_id/events/:hook_log_id/resend" do
        hook = find_hook
        if Feature.enabled?(:web_hook_event_resend_api_endpoint_rate_limit, Feature.current_request)
          check_rate_limit!(:web_hook_event_resend, scope: [hook.parent, current_user])
        end

        web_hook_log = hook.web_hook_logs.find(params[:hook_log_id])
        result = WebHooks::Events::ResendService.new(web_hook_log, current_user: current_user).execute

        if result.success?
          present result, with: Entities::RetryWebhookEvent
        else
          render_api_error!(result.message, 422)
        end
      end
    end
    # rubocop: enable API/Base
  end
end