2020-05-29 17:08:35 -04:00
|
|
|
# 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
|
2020-06-02 08:08:33 -04:00
|
|
|
Gitlab::JiraImport.validate_project_settings!(project, user: user)
|
2020-05-29 17:08:35 -04:00
|
|
|
|
2020-08-18 11:10:33 -04:00
|
|
|
ServiceResponse.success(payload: mapped_users)
|
2020-05-29 17:08:35 -04:00
|
|
|
rescue Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, Errno::ECONNREFUSED, URI::InvalidURIError, JIRA::HTTPError, OpenSSL::SSL::SSLError => error
|
2021-03-12 16:09:12 -05:00
|
|
|
Gitlab::ErrorTracking.log_exception(error, project_id: project.id)
|
2020-08-18 11:10:33 -04:00
|
|
|
ServiceResponse.error(message: "There was an error when communicating to Jira")
|
2020-06-08 11:08:20 -04:00
|
|
|
rescue Projects::ImportService::Error => error
|
|
|
|
ServiceResponse.error(message: error.message)
|
2020-05-29 17:08:35 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2020-11-13 10:09:24 -05:00
|
|
|
attr_reader :user, :project, :start_at
|
|
|
|
|
2020-08-18 11:10:33 -04:00
|
|
|
def mapped_users
|
|
|
|
users_mapper_service.execute
|
|
|
|
end
|
|
|
|
|
|
|
|
def users_mapper_service
|
|
|
|
@users_mapper_service ||= user_mapper_service_factory
|
2020-05-29 17:08:35 -04:00
|
|
|
end
|
|
|
|
|
2020-08-18 11:10:33 -04:00
|
|
|
def user_mapper_service_factory
|
2021-06-18 11:10:16 -04:00
|
|
|
if project.jira_integration.data_fields.deployment_server?
|
2020-11-13 10:09:24 -05:00
|
|
|
ServerUsersMapperService.new(user, project, start_at)
|
2021-06-18 11:10:16 -04:00
|
|
|
elsif project.jira_integration.data_fields.deployment_cloud?
|
2020-11-13 10:09:24 -05:00
|
|
|
CloudUsersMapperService.new(user, project, start_at)
|
2020-08-18 11:10:33 -04:00
|
|
|
else
|
|
|
|
raise ArgumentError
|
|
|
|
end
|
|
|
|
end
|
2020-05-29 17:08:35 -04:00
|
|
|
end
|
|
|
|
end
|