summaryrefslogtreecommitdiff
path: root/app/workers
diff options
context:
space:
mode:
Diffstat (limited to 'app/workers')
-rw-r--r--app/workers/gitlab/jira_import/import_issue_worker.rb32
-rw-r--r--app/workers/gitlab/jira_import/stage/import_labels_worker.rb6
2 files changed, 29 insertions, 9 deletions
diff --git a/app/workers/gitlab/jira_import/import_issue_worker.rb b/app/workers/gitlab/jira_import/import_issue_worker.rb
index 832916a03b6..7ace0a35fd9 100644
--- a/app/workers/gitlab/jira_import/import_issue_worker.rb
+++ b/app/workers/gitlab/jira_import/import_issue_worker.rb
@@ -9,8 +9,8 @@ module Gitlab
include Gitlab::Import::DatabaseHelpers
def perform(project_id, jira_issue_id, issue_attributes, waiter_key)
- issue_id = insert_and_return_id(issue_attributes, Issue)
- cache_issue_mapping(issue_id, jira_issue_id, project_id)
+ issue_id = create_issue(issue_attributes, project_id)
+ JiraImport.cache_issue_mapping(issue_id, jira_issue_id, project_id)
rescue => ex
# Todo: Record jira issue id(or better jira issue key),
# so that we can report the list of failed to import issues to the user
@@ -27,9 +27,31 @@ module Gitlab
private
- def cache_issue_mapping(issue_id, jira_issue_id, project_id)
- cache_key = JiraImport.jira_issue_cache_key(project_id, jira_issue_id)
- Gitlab::Cache::Import::Caching.write(cache_key, issue_id)
+ def create_issue(issue_attributes, project_id)
+ issue_id = insert_and_return_id(issue_attributes, Issue)
+
+ label_issue(project_id, issue_id)
+
+ issue_id
+ end
+
+ def label_issue(project_id, issue_id)
+ label_id = JiraImport.get_import_label_id(project_id)
+ return unless label_id
+
+ label_link_attrs = build_label_attrs(issue_id, label_id.to_i)
+ insert_and_return_id(label_link_attrs, LabelLink)
+ end
+
+ def build_label_attrs(issue_id, label_id)
+ time = Time.now
+ {
+ label_id: label_id,
+ target_id: issue_id,
+ target_type: 'Issue',
+ created_at: time,
+ updated_at: time
+ }
end
end
end
diff --git a/app/workers/gitlab/jira_import/stage/import_labels_worker.rb b/app/workers/gitlab/jira_import/stage/import_labels_worker.rb
index b96bb1bbdda..0499749198a 100644
--- a/app/workers/gitlab/jira_import/stage/import_labels_worker.rb
+++ b/app/workers/gitlab/jira_import/stage/import_labels_worker.rb
@@ -9,10 +9,8 @@ module Gitlab
private
def import(project)
- # fake labels import workers for now
- # new job waiter will have zero jobs_remaining by default, so it will just pass on to next stage
- fake_waiter = JobWaiter.new
- Gitlab::JiraImport::AdvanceStageWorker.perform_async(project.id, { fake_waiter.key => fake_waiter.jobs_remaining }, :issues)
+ job_waiter = Gitlab::JiraImport::LabelsImporter.new(project).execute
+ Gitlab::JiraImport::AdvanceStageWorker.perform_async(project.id, { job_waiter.key => job_waiter.jobs_remaining }, :issues)
end
end
end