Class: Gitlab::GithubImport::Importer::NoteImporter
- Inherits:
-
Object
- Object
- Gitlab::GithubImport::Importer::NoteImporter
- Defined in:
- lib/gitlab/github_import/importer/note_importer.rb
Constant Summary
Constants included from Import::UsernameMentionRewriter
Import::UsernameMentionRewriter::MENTION_REGEX
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#note ⇒ Object
readonly
Returns the value of attribute note.
-
#project ⇒ Object
readonly
Returns the value of attribute project.
-
#user_finder ⇒ Object
readonly
Returns the value of attribute user_finder.
Instance Method Summary collapse
- #execute ⇒ Object
-
#find_noteable_id ⇒ Object
Returns the ID of the issue or merge request to create the note for.
-
#initialize(note, project, client) ⇒ NoteImporter
constructor
note - An instance of
Gitlab::GithubImport::Representation::Note.
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?
Methods included from Import::UsernameMentionRewriter
#update_username_mentions, #wrap_mentions_in_backticks
Constructor Details
#initialize(note, project, client) ⇒ NoteImporter
note - An instance of Gitlab::GithubImport::Representation::Note. project - An instance of Project. client - An instance of Gitlab::GithubImport::Client.
15 16 17 18 19 20 |
# File 'lib/gitlab/github_import/importer/note_importer.rb', line 15 def initialize(note, project, client) @note = note @project = project @client = client @user_finder = GithubImport::UserFinder.new(project, client) end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
10 11 12 |
# File 'lib/gitlab/github_import/importer/note_importer.rb', line 10 def client @client end |
#note ⇒ Object (readonly)
Returns the value of attribute note.
10 11 12 |
# File 'lib/gitlab/github_import/importer/note_importer.rb', line 10 def note @note end |
#project ⇒ Object (readonly)
Returns the value of attribute project.
10 11 12 |
# File 'lib/gitlab/github_import/importer/note_importer.rb', line 10 def project @project end |
#user_finder ⇒ Object (readonly)
Returns the value of attribute user_finder.
10 11 12 |
# File 'lib/gitlab/github_import/importer/note_importer.rb', line 10 def user_finder @user_finder end |
Instance Method Details
#execute ⇒ Object
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 47 48 49 50 51 52 53 54 |
# File 'lib/gitlab/github_import/importer/note_importer.rb', line 22 def execute noteable_id = find_noteable_id raise Exceptions::NoteableNotFound, 'Error to find noteable_id for note' unless noteable_id , = user_finder.(note) attributes = { noteable_type: note.noteable_type, noteable_id: noteable_id, project_id: project.id, namespace_id: project.project_namespace_id, author_id: , note: note_body(), discussion_id: note.discussion_id, system: false, created_at: note.created_at, updated_at: note.updated_at, imported_from: ::Import::HasImportSource::IMPORT_SOURCES[:github] } Note.new(attributes.merge(importing: true)).validate! # We're using bulk_insert here so we can bypass any callbacks. # Running these would result in a lot of unnecessary SQL # queries being executed when importing large projects. # Note: if you're going to replace `legacy_bulk_insert` with something that trigger callback # to generate HTML version - you also need to regenerate it in # Gitlab::GithubImport::Importer::NoteAttachmentsImporter. ids = ApplicationRecord.legacy_bulk_insert(Note.table_name, [attributes], return_ids: true) # rubocop:disable Gitlab/BulkInsert push_references_by_ids(project, ids, Note, :author_id, note[:author]&.id) end |
#find_noteable_id ⇒ Object
Returns the ID of the issue or merge request to create the note for.
57 58 59 |
# File 'lib/gitlab/github_import/importer/note_importer.rb', line 57 def find_noteable_id GithubImport::IssuableFinder.new(project, note).database_id end |