File: events.rb

package info (click to toggle)
gitlab 17.6.5-19
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • 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 (38 lines) | stat: -rw-r--r-- 1,242 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
35
36
37
38
# frozen_string_literal: true

module API
  module Hooks
    # rubocop: disable API/Base -- re-usable module
    class Events < ::Grape::API
      include PaginationParams

      desc 'Get events for a given hook id' do
        detail 'List web hook logs by hook id'
        success code: 200
        failure [
          { code: 400, message: 'Bad request' },
          { code: 404, message: 'Not found' },
          { code: 403, message: 'Forbidden' }
        ]
      end
      params do
        optional :status,
          type: Array[String],
          coerce_with: Validations::Types::CommaSeparatedToArray.coerce,
          values: Rack::Utils::HTTP_STATUS_CODES.keys.map(&:to_s) + %w[successful client_failure server_failure]
        optional :per_page, type: Integer, default: 20,
          desc: 'Number of items per page', documentation: { example: 20 },
          values: 1..20
        use :pagination
      end
      get "events" do
        search_params = declared_params(include_missing: false)
        hook = find_hook

        logs = WebHooks::WebHookLogsFinder.new(hook, current_user, search_params).execute
        present paginate(logs), with: Entities::WebHookLog
      end
    end
    # rubocop: enable API/Base
  end
end