Class: Gitlab::GithubImport::Importer::NoteAttachmentsImporter

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

Constant Summary collapse

SUPPORTED_RECORD_TYPES =
[::Release.name, ::Issue.name, ::MergeRequest.name, ::Note.name].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(note_text, project, client) ⇒ NoteAttachmentsImporter

note_text - An instance of ‘Gitlab::GithubImport::Representation::NoteText`. project - An instance of `Project`. client - An instance of `Gitlab::GithubImport::Client`.



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

def initialize(note_text, project, client)
  @note_text = note_text
  @project = project
  @client = client
  @web_endpoint = client.web_endpoint
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



7
8
9
# File 'lib/gitlab/github_import/importer/note_attachments_importer.rb', line 7

def client
  @client
end

#note_textObject (readonly)

Returns the value of attribute note_text.



7
8
9
# File 'lib/gitlab/github_import/importer/note_attachments_importer.rb', line 7

def note_text
  @note_text
end

#projectObject (readonly)

Returns the value of attribute project.



7
8
9
# File 'lib/gitlab/github_import/importer/note_attachments_importer.rb', line 7

def project
  @project
end

#web_endpointObject (readonly)

Returns the value of attribute web_endpoint.



7
8
9
# File 'lib/gitlab/github_import/importer/note_attachments_importer.rb', line 7

def web_endpoint
  @web_endpoint
end

Instance Method Details

#executeObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/gitlab/github_import/importer/note_attachments_importer.rb', line 21

def execute
  attachments = Gitlab::GithubImport::MarkdownText.fetch_attachments(note_text.text, web_endpoint)
  return if attachments.blank?

  new_text = attachments.reduce(note_text.text) do |text, attachment|
    new_url = gitlab_attachment_link(attachment)

    # we need to update video media file links with the correct markdown format
    if new_url.end_with?(*supported_video_media_types)
      text.gsub(attachment.url, "![media_attachment](#{new_url})")
    else
      text.gsub(attachment.url, new_url)
    end
  end

  update_note_record(new_text)
end