Module: Gitlab::JiraImport

Defined in:
lib/gitlab/jira_import.rb,
lib/gitlab/jira_import/base_importer.rb,
lib/gitlab/jira_import/issues_importer.rb,
lib/gitlab/jira_import/labels_importer.rb,
lib/gitlab/jira_import/issue_serializer.rb,
lib/gitlab/jira_import/metadata_collector.rb,
lib/gitlab/jira_import/handle_labels_service.rb,
app/workers/gitlab/jira_import/import_issue_worker.rb,
app/workers/gitlab/jira_import/advance_stage_worker.rb,
app/workers/concerns/gitlab/jira_import/import_worker.rb,
app/workers/concerns/gitlab/jira_import/queue_options.rb,
app/workers/gitlab/jira_import/stage/import_notes_worker.rb,
app/workers/gitlab/jira_import/stage/start_import_worker.rb,
app/workers/gitlab/jira_import/stage/finish_import_worker.rb,
app/workers/gitlab/jira_import/stage/import_issues_worker.rb,
app/workers/gitlab/jira_import/stage/import_labels_worker.rb,
app/workers/gitlab/jira_import/stuck_jira_import_jobs_worker.rb,
app/workers/gitlab/jira_import/stage/import_attachments_worker.rb

Defined Under Namespace

Modules: ImportWorker, QueueOptions, Stage Classes: AdvanceStageWorker, BaseImporter, HandleLabelsService, ImportIssueWorker, IssueSerializer, IssuesImporter, LabelsImporter, MetadataCollector, StuckJiraImportJobsWorker

Constant Summary collapse

JIRA_IMPORT_CACHE_TIMEOUT =
10.seconds.to_i
FAILED_ISSUES_COUNTER_KEY =
'jira-import/failed/%{project_id}/%{collection_type}'
NEXT_ITEMS_START_AT_KEY =
'jira-import/paginator/%{project_id}/%{collection_type}'
JIRA_IMPORT_LABEL =
'jira-import/import-label/%{project_id}'
ITEMS_MAPPER_CACHE_KEY =
'jira-import/items-mapper/%{project_id}/%{collection_type}/%{jira_item_id}'
USERS_MAPPER_KEY_PREFIX =
'jira-import/items-mapper/%{project_id}/users/'
ALREADY_IMPORTED_ITEMS_CACHE_KEY =
'jira-importer/already-imported/%{project}/%{collection_type}'

Class Method Summary collapse

Class Method Details

.already_imported_cache_key(collection_type, project_id) ⇒ Object


36
37
38
# File 'lib/gitlab/jira_import.rb', line 36

def self.already_imported_cache_key(collection_type, project_id)
  ALREADY_IMPORTED_ITEMS_CACHE_KEY % { collection_type: collection_type, project: project_id }
end

.cache_classObject


102
103
104
# File 'lib/gitlab/jira_import.rb', line 102

def self.cache_class
  Gitlab::Cache::Import::Caching
end

.cache_cleanup(project_id) ⇒ Object


82
83
84
85
86
87
# File 'lib/gitlab/jira_import.rb', line 82

def self.cache_cleanup(project_id)
  cache_class.expire(self.import_label_cache_key(project_id), JIRA_IMPORT_CACHE_TIMEOUT)
  cache_class.expire(self.failed_issues_counter_cache_key(project_id), JIRA_IMPORT_CACHE_TIMEOUT)
  cache_class.expire(self.jira_issues_next_page_cache_key(project_id), JIRA_IMPORT_CACHE_TIMEOUT)
  cache_class.expire(self.already_imported_cache_key(:issues, project_id), JIRA_IMPORT_CACHE_TIMEOUT)
end

.cache_import_label_id(project_id, label_id) ⇒ Object


78
79
80
# File 'lib/gitlab/jira_import.rb', line 78

def self.cache_import_label_id(project_id, label_id)
  cache_class.write(JiraImport.import_label_cache_key(project_id), label_id)
end

.cache_issue_mapping(issue_id, jira_issue_id, project_id) ⇒ Object


69
70
71
72
# File 'lib/gitlab/jira_import.rb', line 69

def self.cache_issue_mapping(issue_id, jira_issue_id, project_id)
  cache_key = JiraImport.jira_item_cache_key(project_id, jira_issue_id, :issues)
  cache_class.write(cache_key, issue_id)
end

.cache_users_mapping(project_id, mapping) ⇒ Object

Caches the mapping of jira_account_id -> gitlab user id project_id - id of a project mapping - hash in format of jira_account_id -> gitlab user id


92
93
94
# File 'lib/gitlab/jira_import.rb', line 92

def self.cache_users_mapping(project_id, mapping)
  cache_class.write_multiple(mapping, key_prefix: jira_user_key_prefix(project_id))
end

.failed_issues_counter_cache_key(project_id) ⇒ Object


44
45
46
# File 'lib/gitlab/jira_import.rb', line 44

def self.failed_issues_counter_cache_key(project_id)
  FAILED_ISSUES_COUNTER_KEY % { project_id: project_id, collection_type: :issues }
end

.get_import_label_id(project_id) ⇒ Object


74
75
76
# File 'lib/gitlab/jira_import.rb', line 74

def self.get_import_label_id(project_id)
  cache_class.read(JiraImport.import_label_cache_key(project_id))
end

.get_issues_next_start_at(project_id) ⇒ Object


60
61
62
# File 'lib/gitlab/jira_import.rb', line 60

def self.get_issues_next_start_at(project_id)
  cache_class.read(self.jira_issues_next_page_cache_key(project_id)).to_i
end

.get_user_mapping(project_id, jira_account_id) ⇒ Object


96
97
98
99
100
# File 'lib/gitlab/jira_import.rb', line 96

def self.get_user_mapping(project_id, )
  cache_key = JiraImport.jira_item_cache_key(project_id, , :users)

  cache_class.read(cache_key)&.to_i
end

.import_label_cache_key(project_id) ⇒ Object


48
49
50
# File 'lib/gitlab/jira_import.rb', line 48

def self.import_label_cache_key(project_id)
  JIRA_IMPORT_LABEL % { project_id: project_id }
end

.increment_issue_failures(project_id) ⇒ Object


52
53
54
# File 'lib/gitlab/jira_import.rb', line 52

def self.increment_issue_failures(project_id)
  cache_class.increment(self.failed_issues_counter_cache_key(project_id))
end

.issue_failures(project_id) ⇒ Object


56
57
58
# File 'lib/gitlab/jira_import.rb', line 56

def self.issue_failures(project_id)
  cache_class.read(self.failed_issues_counter_cache_key(project_id)).to_i
end

.jira_issues_next_page_cache_key(project_id) ⇒ Object


40
41
42
# File 'lib/gitlab/jira_import.rb', line 40

def self.jira_issues_next_page_cache_key(project_id)
  NEXT_ITEMS_START_AT_KEY % { project_id: project_id, collection_type: :issues }
end

.jira_item_cache_key(project_id, jira_item_id, collection_type) ⇒ Object


28
29
30
# File 'lib/gitlab/jira_import.rb', line 28

def self.jira_item_cache_key(project_id, jira_item_id, collection_type)
  ITEMS_MAPPER_CACHE_KEY % { project_id: project_id, collection_type: collection_type, jira_item_id: jira_item_id }
end

.jira_user_key_prefix(project_id) ⇒ Object


32
33
34
# File 'lib/gitlab/jira_import.rb', line 32

def self.jira_user_key_prefix(project_id)
  USERS_MAPPER_KEY_PREFIX % { project_id: project_id }
end

.store_issues_next_started_at(project_id, value) ⇒ Object


64
65
66
67
# File 'lib/gitlab/jira_import.rb', line 64

def self.store_issues_next_started_at(project_id, value)
  cache_key = self.jira_issues_next_page_cache_key(project_id)
  cache_class.write(cache_key, value)
end

.validate_project_settings!(project, user: nil, configuration_check: true) ⇒ Object


14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/gitlab/jira_import.rb', line 14

def self.validate_project_settings!(project, user: nil, configuration_check: true)
  if user
    raise Projects::ImportService::Error, _('Cannot import because issues are not available in this project.') unless project.feature_available?(:issues, user)
    raise Projects::ImportService::Error, _('You do not have permissions to run the import.') unless user.can?(:admin_project, project)
  end

  return unless configuration_check

  jira_service = project.jira_service

  raise Projects::ImportService::Error, _('Jira integration not configured.') unless jira_service&.active?
  raise Projects::ImportService::Error, _('Unable to connect to the Jira instance. Please check your Jira integration configuration.') unless jira_service&.valid_connection?
end