Welcome to mirror list, hosted at ThFree Co, Russian Federation.

base.rb « requests « jira « services « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 7521c7610cb0d6fda0a1d29875ef6490ecb3d954 (plain)
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# frozen_string_literal: true

module Jira
  module Requests
    class Base
      include ProjectServicesLoggable

      PER_PAGE = 50

      attr_reader :jira_service, :project, :limit, :start_at, :query

      def initialize(jira_service, limit: PER_PAGE, start_at: 0, query: nil)
        @project = jira_service&.project
        @jira_service = jira_service

        @limit    = limit
        @start_at = start_at
        @query    = query
      end

      def execute
        return ServiceResponse.error(message: _('Jira service not configured.')) unless jira_service&.active?
        return ServiceResponse.success(payload: empty_payload) if limit.to_i <= 0

        request
      end

      private

      def client
        @client ||= jira_service.client
      end

      def request
        response = client.get(url)
        build_service_response(response)
      rescue Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, Errno::ECONNREFUSED, URI::InvalidURIError, JIRA::HTTPError, OpenSSL::SSL::SSLError => error
        error_message = "Jira request error: #{error.message}"
        log_error("Error sending message", client_url: client.options[:site], error: error_message)
        ServiceResponse.error(message: error_message)
      end

      def url
        raise NotImplementedError
      end

      def build_service_response(response)
        raise NotImplementedError
      end
    end
  end
end