2020-04-01 05:07:45 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Gitlab
|
|
|
|
module JiraImport
|
|
|
|
class LabelsImporter < BaseImporter
|
|
|
|
attr_reader :job_waiter
|
|
|
|
|
2020-04-27 05:09:51 -04:00
|
|
|
MAX_LABELS = 500
|
|
|
|
|
2020-04-01 05:07:45 -04:00
|
|
|
def initialize(project)
|
|
|
|
super
|
|
|
|
@job_waiter = JobWaiter.new
|
|
|
|
end
|
|
|
|
|
|
|
|
def execute
|
2020-04-14 14:09:54 -04:00
|
|
|
cache_import_label(project)
|
2020-04-01 05:07:45 -04:00
|
|
|
import_jira_labels
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2020-04-14 14:09:54 -04:00
|
|
|
def cache_import_label(project)
|
|
|
|
label = project.jira_imports.by_jira_project_key(jira_project_key).last.label
|
2020-04-21 11:21:10 -04:00
|
|
|
raise Projects::ImportService::Error, _('Failed to find import label for Jira import.') unless label
|
2020-04-01 05:07:45 -04:00
|
|
|
|
|
|
|
JiraImport.cache_import_label_id(project.id, label.id)
|
|
|
|
end
|
|
|
|
|
|
|
|
def import_jira_labels
|
2020-04-27 05:09:51 -04:00
|
|
|
start_at = 0
|
|
|
|
loop do
|
|
|
|
break if process_jira_page(start_at)
|
|
|
|
|
|
|
|
start_at += MAX_LABELS
|
|
|
|
end
|
|
|
|
|
2020-04-01 05:07:45 -04:00
|
|
|
job_waiter
|
|
|
|
end
|
2020-04-27 05:09:51 -04:00
|
|
|
|
|
|
|
def process_jira_page(start_at)
|
|
|
|
request = "/rest/api/2/label?maxResults=#{MAX_LABELS}&startAt=#{start_at}"
|
2020-04-30 05:09:39 -04:00
|
|
|
response = client.get(request)
|
2020-04-27 05:09:51 -04:00
|
|
|
|
|
|
|
return true if response['values'].blank?
|
|
|
|
return true unless response.key?('isLast')
|
|
|
|
|
|
|
|
Gitlab::JiraImport::HandleLabelsService.new(project, response['values']).execute
|
|
|
|
|
|
|
|
response['isLast']
|
|
|
|
rescue => e
|
|
|
|
Gitlab::ErrorTracking.track_exception(e, project_id: project.id, request: request)
|
|
|
|
end
|
2020-04-01 05:07:45 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|