Class: Gitlab::GithubImport::Importer::DiffNoteImporter

Inherits:
Object
  • Object
show all
Includes:
Import::PlaceholderReferences::Pusher
Defined in:
lib/gitlab/github_import/importer/diff_note_importer.rb

Constant Summary collapse

DiffNoteCreationError =
Class.new(ActiveRecord::RecordInvalid)

Instance Method Summary collapse

Methods included from Import::PlaceholderReferences::Pusher

#map_to_personal_namespace_owner?, #push_reference, #push_reference_with_composite_key, #push_references_by_ids, #user_mapping_enabled?

Constructor Details

#initialize(note, project, client) ⇒ DiffNoteImporter

note - An instance of Gitlab::GithubImport::Representation::DiffNote project - An instance of Project client - An instance of Gitlab::GithubImport::Client



14
15
16
17
18
# File 'lib/gitlab/github_import/importer/diff_note_importer.rb', line 14

def initialize(note, project, client)
  @note = note
  @project = project
  @client = client
end

Instance Method Details

#executeObject



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/github_import/importer/diff_note_importer.rb', line 20

def execute
  return if merge_request_id.blank?

  note.merge_request = merge_request

  build_author_attributes

  # Diff notes with suggestions are imported with DiffNote, which is
  # slower to import than LegacyDiffNote. Importing DiffNote is slower
  # because it cannot use the BulkImporting strategy, which skips
  # callbacks and validations. For this reason, notes that don't have
  # suggestions are still imported with LegacyDiffNote
  if note.contains_suggestion?
    import_with_diff_note
  else
    import_with_legacy_diff_note
  end
rescue ::DiffNote::NoteDiffFileCreationError, DiffNoteCreationError => e
  Logger.warn(message: e.message, 'error.class': e.class.name)

  import_with_legacy_diff_note
end