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

users_importer.rb « jira_import « services « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 579d367507344b45a7c13a8b49a10b85f81a7c5c (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
# 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