Class: Gitlab::BitbucketImport::Importers::IssueNotesImporter

Inherits:
Object
  • Object
show all
Includes:
ParallelScheduling
Defined in:
lib/gitlab/bitbucket_import/importers/issue_notes_importer.rb

Constant Summary

Constants included from ParallelScheduling

ParallelScheduling::ALREADY_ENQUEUED_CACHE_KEY, ParallelScheduling::JOB_WAITER_CACHE_KEY, ParallelScheduling::JOB_WAITER_REMAINING_CACHE_KEY

Instance Attribute Summary

Attributes included from ParallelScheduling

#already_enqueued_cache_key, #job_waiter_cache_key, #job_waiter_remaining_cache_key, #page_keyset

Instance Method Summary collapse

Methods included from ParallelScheduling

#each_object_to_import

Methods included from ErrorTracking

#track_import_failure!

Methods included from Loggable

#log_debug, #log_error, #log_info, #log_warn, #metrics

Constructor Details

#initialize(project, hash) ⇒ IssueNotesImporter

Returns a new instance of IssueNotesImporter.



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

def initialize(project, hash)
  @project = project
  @formatter = Gitlab::ImportFormatter.new
  @user_finder = UserFinder.new(project)
  @ref_converter = Gitlab::BitbucketImport::RefConverter.new(project)
  @mentions_converter = Gitlab::Import::MentionsConverter.new('bitbucket', project)
  @object = hash.with_indifferent_access
end

Instance Method Details

#executeObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/gitlab/bitbucket_import/importers/issue_notes_importer.rb', line 18

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

  issue = project.issues.find_by(iid: object[:iid]) # rubocop: disable CodeReuse/ActiveRecord

  if issue
    client.issue_comments(project.import_source, issue.iid).each do |comment|
      next unless comment.note.present?

      issue.notes.create!(
        project: project,
        note: comment_note(comment),
        author_id: user_finder.gitlab_user_id(project, comment.author),
        created_at: comment.created_at,
        updated_at: comment.updated_at,
        imported_from: ::Import::SOURCE_BITBUCKET
      )
    end
  end

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