summaryrefslogtreecommitdiff
path: root/app/services/jira_import/users_importer.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/services/jira_import/users_importer.rb')
-rw-r--r--app/services/jira_import/users_importer.rb43
1 files changed, 43 insertions, 0 deletions
diff --git a/app/services/jira_import/users_importer.rb b/app/services/jira_import/users_importer.rb
new file mode 100644
index 00000000000..579d3675073
--- /dev/null
+++ b/app/services/jira_import/users_importer.rb
@@ -0,0 +1,43 @@
+# frozen_string_literal: true
+
+module JiraImport
+ class UsersImporter
+ attr_reader :user, :project, :start_at, :result
+
+ MAX_USERS = 50
+
+ 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)
+
+ return ServiceResponse.success(payload: nil) if users.blank?
+
+ result = UsersMapper.new(project, users).execute
+ ServiceResponse.success(payload: result)
+ rescue Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, Errno::ECONNREFUSED, URI::InvalidURIError, JIRA::HTTPError, OpenSSL::SSL::SSLError => error
+ Gitlab::ErrorTracking.track_exception(error, project_id: project.id, request: url)
+ ServiceResponse.error(message: "There was an error when communicating to Jira: #{error.message}")
+ rescue Projects::ImportService::Error => error
+ ServiceResponse.error(message: error.message)
+ end
+
+ private
+
+ def users
+ @users ||= client.get(url)
+ end
+
+ def url
+ "/rest/api/2/users?maxResults=#{MAX_USERS}&startAt=#{start_at.to_i}"
+ end
+
+ def client
+ @client ||= project.jira_service.client
+ end
+ end
+end