debian-mirror-gitlab/lib/gitlab/jira_import/labels_importer.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

56 lines
1.4 KiB
Ruby
Raw Normal View History

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