debian-mirror-gitlab/app/services/jira_import/users_importer.rb

45 lines
1.3 KiB
Ruby
Raw Normal View History

2020-06-23 00:09:42 +05:30
# frozen_string_literal: true
module JiraImport
class UsersImporter
def initialize(user, project, start_at)
@project = project
@start_at = start_at
@user = user
end
def execute
Gitlab::JiraImport.validate_project_settings!(project, user: user)
2020-10-24 23:57:45 +05:30
ServiceResponse.success(payload: mapped_users)
2020-06-23 00:09:42 +05:30
rescue Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, Errno::ECONNREFUSED, URI::InvalidURIError, JIRA::HTTPError, OpenSSL::SSL::SSLError => error
2021-04-17 20:07:23 +05:30
Gitlab::ErrorTracking.log_exception(error, project_id: project.id)
2020-10-24 23:57:45 +05:30
ServiceResponse.error(message: "There was an error when communicating to Jira")
2020-06-23 00:09:42 +05:30
rescue Projects::ImportService::Error => error
ServiceResponse.error(message: error.message)
end
private
2021-01-29 00:20:46 +05:30
attr_reader :user, :project, :start_at
2020-10-24 23:57:45 +05:30
def mapped_users
users_mapper_service.execute
end
def users_mapper_service
@users_mapper_service ||= user_mapper_service_factory
2020-06-23 00:09:42 +05:30
end
2020-10-24 23:57:45 +05:30
def user_mapper_service_factory
2021-09-30 23:02:18 +05:30
if project.jira_integration.data_fields.deployment_server?
2021-01-29 00:20:46 +05:30
ServerUsersMapperService.new(user, project, start_at)
2021-09-30 23:02:18 +05:30
elsif project.jira_integration.data_fields.deployment_cloud?
2021-01-29 00:20:46 +05:30
CloudUsersMapperService.new(user, project, start_at)
2020-10-24 23:57:45 +05:30
else
raise ArgumentError
end
end
2020-06-23 00:09:42 +05:30
end
end