Class: Gitlab::GithubImport::Importer::NoteAttachmentsImporter
- Inherits:
-
Object
- Object
- Gitlab::GithubImport::Importer::NoteAttachmentsImporter
- 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
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#note_text ⇒ Object
readonly
Returns the value of attribute note_text.
-
#project ⇒ Object
readonly
Returns the value of attribute project.
-
#web_endpoint ⇒ Object
readonly
Returns the value of attribute web_endpoint.
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(note_text, project, client) ⇒ NoteAttachmentsImporter
constructor
note_text - An instance of ‘Gitlab::GithubImport::Representation::NoteText`.
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
#client ⇒ Object (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_text ⇒ Object (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 |
#project ⇒ Object (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_endpoint ⇒ Object (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
#execute ⇒ Object
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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/gitlab/github_import/importer/note_attachments_importer.rb', line 21 def execute = Gitlab::GithubImport::MarkdownText.(note_text.text, web_endpoint) return if .blank? download_errors = [] updated_count = 0 unmodified_count = 0 rate_limit_error = nil new_text = .uniq(&:url).reduce(note_text.text) do |text, | new_url = () if new_url != .url updated_count += 1 else unmodified_count += 1 end # we need to update video media file links with the correct markdown format if new_url.end_with?(*supported_video_media_types) text.gsub(.url, "") else text.gsub(.url, new_url) end rescue Gitlab::GithubImport::RateLimitError => e # Store the error to re-raise after updating the note rate_limit_error ||= e # Continue with the current text without replacing this attachment text rescue Gitlab::GithubImport::AttachmentsDownloader::NotRetriableError => e # Rescue 4XX errors download_errors << e text end if updated_count > 0 update_note_record(new_text) Gitlab::GithubImport::ObjectCounter.increment( project, note_text.object_type, :imported, value: updated_count ) end raise rate_limit_error if rate_limit_error if unmodified_count > 0 Gitlab::GithubImport::ObjectCounter.increment( project, note_text.object_type, :imported, value: unmodified_count ) end save_download_errors(download_errors) end |