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

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

Constant Summary collapse

DiffNoteCreationError =
Class.new(ActiveRecord::RecordInvalid)

Instance Method Summary collapse

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`



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

def initialize(note, project, client)
  @note = note
  @project = project
  @client = client
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
42
43
44
45
46
# File 'lib/gitlab/github_import/importer/diff_note_importer.rb', line 18

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
rescue ActiveRecord::InvalidForeignKey => e
  # It's possible the project and the issue have been deleted since
  # scheduling this job. In this case we'll just skip creating the note
  Logger.info(
    message: e.message,
    github_identifiers: note.github_identifiers
  )
end