Class: Gitlab::BitbucketImport::Importers::IssueImporter

Inherits:
Object
  • Object
show all
Includes:
ErrorTracking, Loggable
Defined in:
lib/gitlab/bitbucket_import/importers/issue_importer.rb

Instance Method Summary collapse

Methods included from ErrorTracking

#track_import_failure!

Methods included from Loggable

#log_debug, #log_error, #log_info, #log_warn

Constructor Details

#initialize(project, hash) ⇒ IssueImporter

Returns a new instance of IssueImporter.



10
11
12
13
14
15
# File 'lib/gitlab/bitbucket_import/importers/issue_importer.rb', line 10

def initialize(project, hash)
  @project = project
  @formatter = Gitlab::ImportFormatter.new
  @user_finder = UserFinder.new(project)
  @object = hash.with_indifferent_access
end

Instance Method Details

#executeObject



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
44
45
46
# File 'lib/gitlab/bitbucket_import/importers/issue_importer.rb', line 17

def execute
  log_info(import_stage: 'import_issue', message: 'starting', iid: object[:iid])

  description = ''
  description += author_line
  description += object[:description] if object[:description]

  milestone = object[:milestone] ? project.milestones.find_or_create_by(title: object[:milestone]) : nil # rubocop: disable CodeReuse/ActiveRecord

  attributes = {
    iid: object[:iid],
    title: object[:title],
    description: description,
    state_id: Issue.available_states[object[:state]],
    author_id: author_id,
    assignee_ids: [author_id],
    namespace_id: project.project_namespace_id,
    milestone: milestone,
    work_item_type_id: object[:issue_type_id],
    label_ids: [object[:label_id]].compact,
    created_at: object[:created_at],
    updated_at: object[:updated_at]
  }

  project.issues.create!(attributes)

  log_info(import_stage: 'import_issue', message: 'finished', iid: object[:iid])
rescue StandardError => e
  track_import_failure!(project, exception: e)
end