debian-mirror-gitlab/app/services/jira/requests/base.rb

67 lines
1.9 KiB
Ruby
Raw Normal View History

2020-06-23 00:09:42 +05:30
# frozen_string_literal: true
module Jira
module Requests
class Base
include ProjectServicesLoggable
2020-07-28 23:09:34 +05:30
JIRA_API_VERSION = 2
2020-06-23 00:09:42 +05:30
2021-09-30 23:02:18 +05:30
def initialize(jira_integration, params = {})
@project = jira_integration&.project
@jira_integration = jira_integration
2020-06-23 00:09:42 +05:30
end
def execute
2021-09-30 23:02:18 +05:30
return ServiceResponse.error(message: _('Jira service not configured.')) unless jira_integration&.active?
2020-06-23 00:09:42 +05:30
request
end
2021-03-11 19:13:27 +05:30
private
2021-09-30 23:02:18 +05:30
attr_reader :jira_integration, :project
2021-03-11 19:13:27 +05:30
2021-02-22 17:27:13 +05:30
# We have to add the context_path here because the Jira client is not taking it into account
2020-07-28 23:09:34 +05:30
def base_api_url
2021-02-22 17:27:13 +05:30
"#{context_path}/rest/api/#{api_version}"
2020-07-28 23:09:34 +05:30
end
2021-02-22 17:27:13 +05:30
def context_path
client.options[:context_path].to_s
end
2020-07-28 23:09:34 +05:30
# override this method in the specific request class implementation if a differnt API version is required
def api_version
JIRA_API_VERSION
end
2020-06-23 00:09:42 +05:30
def client
2021-09-30 23:02:18 +05:30
@client ||= jira_integration.client
2020-06-23 00:09:42 +05:30
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}"
2021-01-03 14:25:43 +05:30
log_error("Error sending message", client_url: client.options[:site],
error: {
exception_class: error.class.name,
exception_message: error.message,
exception_backtrace: Gitlab::BacktraceCleaner.clean_backtrace(error.backtrace)
})
2020-06-23 00:09:42 +05:30
ServiceResponse.error(message: error_message)
end
def url
raise NotImplementedError
end
def build_service_response(response)
raise NotImplementedError
end
end
end
end