Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'lib/gitlab/github_import/importer')
-rw-r--r--lib/gitlab/github_import/importer/attachments/base_importer.rb55
-rw-r--r--lib/gitlab/github_import/importer/attachments/issues_importer.rb37
-rw-r--r--lib/gitlab/github_import/importer/attachments/merge_requests_importer.rb37
-rw-r--r--lib/gitlab/github_import/importer/attachments/notes_importer.rb35
-rw-r--r--lib/gitlab/github_import/importer/attachments/releases_importer.rb33
-rw-r--r--lib/gitlab/github_import/importer/diff_notes_importer.rb2
-rw-r--r--lib/gitlab/github_import/importer/issue_events_importer.rb2
-rw-r--r--lib/gitlab/github_import/importer/issues_importer.rb6
-rw-r--r--lib/gitlab/github_import/importer/labels_importer.rb6
-rw-r--r--lib/gitlab/github_import/importer/milestones_importer.rb16
-rw-r--r--lib/gitlab/github_import/importer/note_attachments_importer.rb57
-rw-r--r--lib/gitlab/github_import/importer/note_importer.rb3
-rw-r--r--lib/gitlab/github_import/importer/notes_importer.rb2
-rw-r--r--lib/gitlab/github_import/importer/protected_branch_importer.rb99
-rw-r--r--lib/gitlab/github_import/importer/protected_branches_importer.rb6
-rw-r--r--lib/gitlab/github_import/importer/pull_requests_importer.rb6
-rw-r--r--lib/gitlab/github_import/importer/pull_requests_reviews_importer.rb6
-rw-r--r--lib/gitlab/github_import/importer/release_attachments_importer.rb58
-rw-r--r--lib/gitlab/github_import/importer/releases_attachments_importer.rb59
-rw-r--r--lib/gitlab/github_import/importer/releases_importer.rb19
-rw-r--r--lib/gitlab/github_import/importer/single_endpoint_issue_events_importer.rb10
21 files changed, 400 insertions, 154 deletions
diff --git a/lib/gitlab/github_import/importer/attachments/base_importer.rb b/lib/gitlab/github_import/importer/attachments/base_importer.rb
new file mode 100644
index 00000000000..eaff99aed43
--- /dev/null
+++ b/lib/gitlab/github_import/importer/attachments/base_importer.rb
@@ -0,0 +1,55 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module GithubImport
+ module Importer
+ module Attachments
+ class BaseImporter
+ include ParallelScheduling
+
+ BATCH_SIZE = 100
+
+ # The method that will be called for traversing through all the objects to
+ # import, yielding them to the supplied block.
+ def each_object_to_import
+ collection.each_batch(of: BATCH_SIZE, column: ordering_column) do |batch|
+ batch.each do |record|
+ next if already_imported?(record)
+
+ Gitlab::GithubImport::ObjectCounter.increment(project, object_type, :fetched)
+
+ yield record
+
+ # We mark the object as imported immediately so we don't end up
+ # scheduling it multiple times.
+ mark_as_imported(record)
+ end
+ end
+ end
+
+ def representation_class
+ Representation::NoteText
+ end
+
+ def importer_class
+ NoteAttachmentsImporter
+ end
+
+ private
+
+ def collection
+ raise Gitlab::GithubImport::Exceptions::NotImplementedError, '#collection'
+ end
+
+ def ordering_column
+ :id
+ end
+
+ def object_representation(object)
+ representation_class.from_db_record(object)
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/lib/gitlab/github_import/importer/attachments/issues_importer.rb b/lib/gitlab/github_import/importer/attachments/issues_importer.rb
new file mode 100644
index 00000000000..090bfb4a098
--- /dev/null
+++ b/lib/gitlab/github_import/importer/attachments/issues_importer.rb
@@ -0,0 +1,37 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module GithubImport
+ module Importer
+ module Attachments
+ class IssuesImporter < ::Gitlab::GithubImport::Importer::Attachments::BaseImporter
+ def sidekiq_worker_class
+ ::Gitlab::GithubImport::Attachments::ImportIssueWorker
+ end
+
+ def collection_method
+ :issue_attachments
+ end
+
+ def object_type
+ :issue_attachment
+ end
+
+ def id_for_already_imported_cache(issue)
+ issue.id
+ end
+
+ private
+
+ def collection
+ project.issues.select(:id, :description)
+ end
+
+ def ordering_column
+ :iid
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/lib/gitlab/github_import/importer/attachments/merge_requests_importer.rb b/lib/gitlab/github_import/importer/attachments/merge_requests_importer.rb
new file mode 100644
index 00000000000..f41071b1785
--- /dev/null
+++ b/lib/gitlab/github_import/importer/attachments/merge_requests_importer.rb
@@ -0,0 +1,37 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module GithubImport
+ module Importer
+ module Attachments
+ class MergeRequestsImporter < ::Gitlab::GithubImport::Importer::Attachments::BaseImporter
+ def sidekiq_worker_class
+ ::Gitlab::GithubImport::Attachments::ImportMergeRequestWorker
+ end
+
+ def collection_method
+ :merge_request_attachments
+ end
+
+ def object_type
+ :merge_request_attachment
+ end
+
+ def id_for_already_imported_cache(merge_request)
+ merge_request.id
+ end
+
+ private
+
+ def collection
+ project.merge_requests.select(:id, :description)
+ end
+
+ def ordering_column
+ :iid
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/lib/gitlab/github_import/importer/attachments/notes_importer.rb b/lib/gitlab/github_import/importer/attachments/notes_importer.rb
new file mode 100644
index 00000000000..aa38a7a3a3f
--- /dev/null
+++ b/lib/gitlab/github_import/importer/attachments/notes_importer.rb
@@ -0,0 +1,35 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module GithubImport
+ module Importer
+ module Attachments
+ class NotesImporter < ::Gitlab::GithubImport::Importer::Attachments::BaseImporter
+ def sidekiq_worker_class
+ ::Gitlab::GithubImport::Attachments::ImportNoteWorker
+ end
+
+ def collection_method
+ :note_attachments
+ end
+
+ def object_type
+ :note_attachment
+ end
+
+ def id_for_already_imported_cache(note)
+ note.id
+ end
+
+ private
+
+ # TODO: exclude :system, :noteable_type from select after removing override Note#note method
+ # https://gitlab.com/gitlab-org/gitlab/-/issues/369923
+ def collection
+ project.notes.user.select(:id, :note, :system, :noteable_type)
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/lib/gitlab/github_import/importer/attachments/releases_importer.rb b/lib/gitlab/github_import/importer/attachments/releases_importer.rb
new file mode 100644
index 00000000000..feaa69eff71
--- /dev/null
+++ b/lib/gitlab/github_import/importer/attachments/releases_importer.rb
@@ -0,0 +1,33 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module GithubImport
+ module Importer
+ module Attachments
+ class ReleasesImporter < ::Gitlab::GithubImport::Importer::Attachments::BaseImporter
+ def sidekiq_worker_class
+ ::Gitlab::GithubImport::Attachments::ImportReleaseWorker
+ end
+
+ def collection_method
+ :release_attachments
+ end
+
+ def object_type
+ :release_attachment
+ end
+
+ def id_for_already_imported_cache(release)
+ release.id
+ end
+
+ private
+
+ def collection
+ project.releases.select(:id, :description)
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/lib/gitlab/github_import/importer/diff_notes_importer.rb b/lib/gitlab/github_import/importer/diff_notes_importer.rb
index 49cbc8f7a42..92f26692a05 100644
--- a/lib/gitlab/github_import/importer/diff_notes_importer.rb
+++ b/lib/gitlab/github_import/importer/diff_notes_importer.rb
@@ -27,7 +27,7 @@ module Gitlab
end
def id_for_already_imported_cache(note)
- note.id
+ note[:id]
end
end
end
diff --git a/lib/gitlab/github_import/importer/issue_events_importer.rb b/lib/gitlab/github_import/importer/issue_events_importer.rb
index 71dd99f91f9..a1c706c5d78 100644
--- a/lib/gitlab/github_import/importer/issue_events_importer.rb
+++ b/lib/gitlab/github_import/importer/issue_events_importer.rb
@@ -27,7 +27,7 @@ module Gitlab
end
def id_for_already_imported_cache(event)
- event.id
+ event[:id]
end
end
end
diff --git a/lib/gitlab/github_import/importer/issues_importer.rb b/lib/gitlab/github_import/importer/issues_importer.rb
index 21d9ce8cd2d..3d6f15fc2bc 100644
--- a/lib/gitlab/github_import/importer/issues_importer.rb
+++ b/lib/gitlab/github_import/importer/issues_importer.rb
@@ -33,13 +33,17 @@ module Gitlab
end
def id_for_already_imported_cache(issue)
- issue.number
+ issue[:number]
end
def collection_options
{ state: 'all', sort: 'created', direction: 'asc' }
end
+ def increment_object_counter?(object)
+ object[:pull_request].nil?
+ end
+
private
def additional_object_data
diff --git a/lib/gitlab/github_import/importer/labels_importer.rb b/lib/gitlab/github_import/importer/labels_importer.rb
index 7293de56a9a..9a011f17a18 100644
--- a/lib/gitlab/github_import/importer/labels_importer.rb
+++ b/lib/gitlab/github_import/importer/labels_importer.rb
@@ -22,7 +22,7 @@ module Gitlab
end
def already_imported?(label)
- existing_labels.include?(label.name)
+ existing_labels.include?(label[:name])
end
def build_labels_cache
@@ -33,8 +33,8 @@ module Gitlab
time = Time.zone.now
{
- title: label.name,
- color: '#' + label.color,
+ title: label[:name],
+ color: '#' + label[:color],
project_id: project.id,
type: 'ProjectLabel',
created_at: time,
diff --git a/lib/gitlab/github_import/importer/milestones_importer.rb b/lib/gitlab/github_import/importer/milestones_importer.rb
index d11b151bbe2..1a3a54d0053 100644
--- a/lib/gitlab/github_import/importer/milestones_importer.rb
+++ b/lib/gitlab/github_import/importer/milestones_importer.rb
@@ -22,7 +22,7 @@ module Gitlab
end
def already_imported?(milestone)
- existing_milestones.include?(milestone.number)
+ existing_milestones.include?(milestone[:number])
end
def build_milestones_cache
@@ -31,19 +31,19 @@ module Gitlab
def build(milestone)
{
- iid: milestone.number,
- title: milestone.title,
- description: milestone.description,
+ iid: milestone[:number],
+ title: milestone[:title],
+ description: milestone[:description],
project_id: project.id,
state: state_for(milestone),
- due_date: milestone.due_on&.to_date,
- created_at: milestone.created_at,
- updated_at: milestone.updated_at
+ due_date: milestone[:due_on]&.to_date,
+ created_at: milestone[:created_at],
+ updated_at: milestone[:updated_at]
}
end
def state_for(milestone)
- milestone.state == 'open' ? :active : :closed
+ milestone[:state] == 'open' ? :active : :closed
end
def each_milestone
diff --git a/lib/gitlab/github_import/importer/note_attachments_importer.rb b/lib/gitlab/github_import/importer/note_attachments_importer.rb
new file mode 100644
index 00000000000..9901c9e76f5
--- /dev/null
+++ b/lib/gitlab/github_import/importer/note_attachments_importer.rb
@@ -0,0 +1,57 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module GithubImport
+ module Importer
+ class NoteAttachmentsImporter
+ attr_reader :note_text, :project
+
+ # note_text - An instance of `NoteText`.
+ # project - An instance of `Project`.
+ # client - An instance of `Gitlab::GithubImport::Client`.
+ def initialize(note_text, project, _client = nil)
+ @note_text = note_text
+ @project = project
+ end
+
+ def execute
+ attachments = MarkdownText.fetch_attachments(note_text.text)
+ return if attachments.blank?
+
+ new_text = attachments.reduce(note_text.text) do |text, attachment|
+ new_url = download_attachment(attachment)
+ text.gsub(attachment.url, new_url)
+ end
+
+ update_note_record(new_text)
+ end
+
+ private
+
+ # in: an instance of Gitlab::GithubImport::Markdown::Attachment
+ # out: gitlab attachment markdown url
+ def download_attachment(attachment)
+ downloader = ::Gitlab::GithubImport::AttachmentsDownloader.new(attachment.url)
+ file = downloader.perform
+ uploader = UploadService.new(project, file, FileUploader).execute
+ uploader.to_h[:url]
+ ensure
+ downloader&.delete
+ end
+
+ def update_note_record(text)
+ case note_text.record_type
+ when ::Release.name
+ ::Release.find(note_text.record_db_id).update_column(:description, text)
+ when ::Issue.name
+ ::Issue.find(note_text.record_db_id).update_column(:description, text)
+ when ::MergeRequest.name
+ ::MergeRequest.find(note_text.record_db_id).update_column(:description, text)
+ when ::Note.name
+ ::Note.find(note_text.record_db_id).update_column(:note, text)
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/lib/gitlab/github_import/importer/note_importer.rb b/lib/gitlab/github_import/importer/note_importer.rb
index 1410006af26..69b7b2c2a38 100644
--- a/lib/gitlab/github_import/importer/note_importer.rb
+++ b/lib/gitlab/github_import/importer/note_importer.rb
@@ -36,6 +36,9 @@ module Gitlab
# We're using bulk_insert here so we can bypass any validations and
# 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.
ApplicationRecord.legacy_bulk_insert(Note.table_name, [attributes]) # rubocop:disable Gitlab/BulkInsert
rescue ActiveRecord::InvalidForeignKey
# It's possible the project and the issue have been deleted since
diff --git a/lib/gitlab/github_import/importer/notes_importer.rb b/lib/gitlab/github_import/importer/notes_importer.rb
index ca1d7d60515..4c2b87a8c5e 100644
--- a/lib/gitlab/github_import/importer/notes_importer.rb
+++ b/lib/gitlab/github_import/importer/notes_importer.rb
@@ -27,7 +27,7 @@ module Gitlab
end
def id_for_already_imported_cache(note)
- note.id
+ note[:id]
end
end
end
diff --git a/lib/gitlab/github_import/importer/protected_branch_importer.rb b/lib/gitlab/github_import/importer/protected_branch_importer.rb
index 16215fdce8e..21075e21e1d 100644
--- a/lib/gitlab/github_import/importer/protected_branch_importer.rb
+++ b/lib/gitlab/github_import/importer/protected_branch_importer.rb
@@ -6,6 +6,10 @@ module Gitlab
class ProtectedBranchImporter
attr_reader :protected_branch, :project, :client
+ # By default on GitHub, both developers and maintainers can merge
+ # a PR into the protected branch
+ GITHUB_DEFAULT_MERGE_ACCESS_LEVEL = Gitlab::Access::DEVELOPER
+
# protected_branch - An instance of
# `Gitlab::GithubImport::Representation::ProtectedBranch`.
# project - An instance of `Project`
@@ -22,6 +26,8 @@ module Gitlab
ProtectedBranches::CreateService
.new(project, project.creator, params)
.execute(skip_authorization: true)
+
+ update_project_settings if default_branch?
end
private
@@ -29,8 +35,8 @@ module Gitlab
def params
{
name: protected_branch.id,
- push_access_levels_attributes: [{ access_level: Gitlab::Access::MAINTAINER }],
- merge_access_levels_attributes: [{ access_level: Gitlab::Access::MAINTAINER }],
+ push_access_levels_attributes: [{ access_level: push_access_level }],
+ merge_access_levels_attributes: [{ access_level: merge_access_level }],
allow_force_push: allow_force_push?
}
end
@@ -42,6 +48,95 @@ module Gitlab
protected_branch.allow_force_pushes
end
end
+
+ def default_branch?
+ protected_branch.id == project.default_branch
+ end
+
+ def update_project_settings
+ update_setting_for_only_allow_merge_if_all_discussions_are_resolved
+ update_project_push_rule
+ end
+
+ def update_setting_for_only_allow_merge_if_all_discussions_are_resolved
+ return unless protected_branch.required_conversation_resolution
+
+ project.update(only_allow_merge_if_all_discussions_are_resolved: true)
+ end
+
+ def update_project_push_rule
+ return unless project.licensed_feature_available?(:push_rules)
+ return unless protected_branch.required_signatures
+
+ push_rule = project.push_rule || project.build_push_rule
+ push_rule.update!(reject_unsigned_commits: true)
+ project.project_setting.update!(push_rule_id: push_rule.id)
+ end
+
+ def push_access_level
+ if protected_branch.required_pull_request_reviews
+ Gitlab::Access::NO_ACCESS
+ else
+ gitlab_access_level_for(:push)
+ end
+ end
+
+ # Gets the strictest merge_access_level between GitHub and GitLab
+ def merge_access_level
+ gitlab_access = gitlab_access_level_for(:merge)
+
+ return gitlab_access if gitlab_access == Gitlab::Access::NO_ACCESS
+
+ [gitlab_access, GITHUB_DEFAULT_MERGE_ACCESS_LEVEL].max
+ end
+
+ # action - :push/:merge
+ def gitlab_access_level_for(action)
+ if default_branch?
+ action == :push ? default_branch_push_access_level : default_branch_merge_access_level
+ elsif protected_on_gitlab?
+ non_default_branch_access_level_for(action)
+ else
+ gitlab_default_access_level_for(action)
+ end
+ end
+
+ def default_branch_push_access_level
+ if default_branch_protection.developer_can_push?
+ Gitlab::Access::DEVELOPER
+ else
+ gitlab_default_access_level_for(:push)
+ end
+ end
+
+ def default_branch_merge_access_level
+ if default_branch_protection.developer_can_merge?
+ Gitlab::Access::DEVELOPER
+ else
+ gitlab_default_access_level_for(:merge)
+ end
+ end
+
+ def default_branch_protection
+ Gitlab::Access::BranchProtection.new(project.namespace.default_branch_protection)
+ end
+
+ def protected_on_gitlab?
+ ProtectedBranch.protected?(project, protected_branch.id)
+ end
+
+ def non_default_branch_access_level_for(action)
+ access_level = ProtectedBranch.access_levels_for_ref(protected_branch.id, action: action)
+ .find(&:role?)&.access_level
+
+ access_level || gitlab_default_access_level_for(action)
+ end
+
+ def gitlab_default_access_level_for(action)
+ return ProtectedBranch::PushAccessLevel::GITLAB_DEFAULT_ACCESS_LEVEL if action == :push
+
+ ProtectedBranch::MergeAccessLevel::GITLAB_DEFAULT_ACCESS_LEVEL
+ end
end
end
end
diff --git a/lib/gitlab/github_import/importer/protected_branches_importer.rb b/lib/gitlab/github_import/importer/protected_branches_importer.rb
index b5be823d5ab..4372477f55d 100644
--- a/lib/gitlab/github_import/importer/protected_branches_importer.rb
+++ b/lib/gitlab/github_import/importer/protected_branches_importer.rb
@@ -11,9 +11,9 @@ module Gitlab
def each_object_to_import
repo = project.import_source
- protected_branches = client.branches(repo).select { |branch| branch.protection&.enabled }
+ protected_branches = client.branches(repo).select { |branch| branch.dig(:protection, :enabled) }
protected_branches.each do |protected_branch|
- object = client.branch_protection(repo, protected_branch.name)
+ object = client.branch_protection(repo, protected_branch[:name])
next if object.nil? || already_imported?(object)
yield object
@@ -44,7 +44,7 @@ module Gitlab
end
def id_for_already_imported_cache(protected_branch)
- protected_branch.name
+ protected_branch[:name]
end
end
end
diff --git a/lib/gitlab/github_import/importer/pull_requests_importer.rb b/lib/gitlab/github_import/importer/pull_requests_importer.rb
index 5d291d9d723..16541c90002 100644
--- a/lib/gitlab/github_import/importer/pull_requests_importer.rb
+++ b/lib/gitlab/github_import/importer/pull_requests_importer.rb
@@ -19,7 +19,7 @@ module Gitlab
end
def id_for_already_imported_cache(pr)
- pr.number
+ pr[:number]
end
def object_type
@@ -55,11 +55,11 @@ module Gitlab
def update_repository?(pr)
last_update = project.last_repository_updated_at || project.created_at
- return false if pr.updated_at < last_update
+ return false if pr[:updated_at] < last_update
# PRs may be updated without there actually being new commits, thus we
# check to make sure we only re-fetch if truly necessary.
- !(commit_exists?(pr.head.sha) && commit_exists?(pr.base.sha))
+ !(commit_exists?(pr.dig(:head, :sha)) && commit_exists?(pr.dig(:base, :sha)))
end
def commit_exists?(sha)
diff --git a/lib/gitlab/github_import/importer/pull_requests_reviews_importer.rb b/lib/gitlab/github_import/importer/pull_requests_reviews_importer.rb
index 5e55d09fe3d..543c29a21a0 100644
--- a/lib/gitlab/github_import/importer/pull_requests_reviews_importer.rb
+++ b/lib/gitlab/github_import/importer/pull_requests_reviews_importer.rb
@@ -34,7 +34,7 @@ module Gitlab
end
def id_for_already_imported_cache(review)
- review.id
+ review[:id]
end
# The worker can be interrupted, by rate limit for instance,
@@ -48,11 +48,13 @@ module Gitlab
def each_object_to_import(&block)
each_review_page do |page, merge_request|
page.objects.each do |review|
+ review = review.to_h
+
next if already_imported?(review)
Gitlab::GithubImport::ObjectCounter.increment(project, object_type, :fetched)
- review.merge_request_id = merge_request.id
+ review[:merge_request_id] = merge_request.id
yield(review)
mark_as_imported(review)
diff --git a/lib/gitlab/github_import/importer/release_attachments_importer.rb b/lib/gitlab/github_import/importer/release_attachments_importer.rb
deleted file mode 100644
index 6419851623c..00000000000
--- a/lib/gitlab/github_import/importer/release_attachments_importer.rb
+++ /dev/null
@@ -1,58 +0,0 @@
-# frozen_string_literal: true
-
-module Gitlab
- module GithubImport
- module Importer
- class ReleaseAttachmentsImporter
- attr_reader :release_db_id, :release_description, :project
-
- # release - An instance of `ReleaseAttachments`.
- # project - An instance of `Project`.
- # client - An instance of `Gitlab::GithubImport::Client`.
- def initialize(release_attachments, project, _client = nil)
- @release_db_id = release_attachments.release_db_id
- @release_description = release_attachments.description
- @project = project
- end
-
- def execute
- attachment_urls = MarkdownText.fetch_attachment_urls(release_description)
- new_description = attachment_urls.reduce(release_description) do |description, url|
- new_url = download_attachment(url)
- description.gsub(url, new_url)
- end
-
- Release.find(release_db_id).update_column(:description, new_description)
- end
-
- private
-
- # in: github attachment markdown url
- # out: gitlab attachment markdown url
- def download_attachment(markdown_url)
- url = extract_url_from_markdown(markdown_url)
- name_prefix = extract_name_from_markdown(markdown_url)
-
- downloader = ::Gitlab::GithubImport::AttachmentsDownloader.new(url)
- file = downloader.perform
- uploader = UploadService.new(project, file, FileUploader).execute
- "#{name_prefix}(#{uploader.to_h[:url]})"
- ensure
- downloader&.delete
- end
-
- # in: "![image-icon](https://user-images.githubusercontent.com/..)"
- # out: https://user-images.githubusercontent.com/..
- def extract_url_from_markdown(text)
- text.match(%r{https://.*\)$}).to_a[0].chop
- end
-
- # in: "![image-icon](https://user-images.githubusercontent.com/..)"
- # out: ![image-icon]
- def extract_name_from_markdown(text)
- text.match(%r{^!?\[.*\]}).to_a[0]
- end
- end
- end
- end
-end
diff --git a/lib/gitlab/github_import/importer/releases_attachments_importer.rb b/lib/gitlab/github_import/importer/releases_attachments_importer.rb
deleted file mode 100644
index 7221c802d83..00000000000
--- a/lib/gitlab/github_import/importer/releases_attachments_importer.rb
+++ /dev/null
@@ -1,59 +0,0 @@
-# frozen_string_literal: true
-
-module Gitlab
- module GithubImport
- module Importer
- class ReleasesAttachmentsImporter
- include ParallelScheduling
-
- BATCH_SIZE = 100
-
- # The method that will be called for traversing through all the objects to
- # import, yielding them to the supplied block.
- def each_object_to_import
- project.releases.select(:id, :description).each_batch(of: BATCH_SIZE, column: :id) do |batch|
- batch.each do |release|
- next if already_imported?(release)
-
- Gitlab::GithubImport::ObjectCounter.increment(project, object_type, :fetched)
-
- yield release
-
- # We mark the object as imported immediately so we don't end up
- # scheduling it multiple times.
- mark_as_imported(release)
- end
- end
- end
-
- def representation_class
- Representation::ReleaseAttachments
- end
-
- def importer_class
- ReleaseAttachmentsImporter
- end
-
- def sidekiq_worker_class
- ImportReleaseAttachmentsWorker
- end
-
- def collection_method
- :release_attachments
- end
-
- def object_type
- :release_attachment
- end
-
- def id_for_already_imported_cache(release)
- release.id
- end
-
- def object_representation(object)
- representation_class.from_db_record(object)
- end
- end
- end
- end
-end
diff --git a/lib/gitlab/github_import/importer/releases_importer.rb b/lib/gitlab/github_import/importer/releases_importer.rb
index 51d364772d2..fe6da30bbf8 100644
--- a/lib/gitlab/github_import/importer/releases_importer.rb
+++ b/lib/gitlab/github_import/importer/releases_importer.rb
@@ -12,6 +12,9 @@ module Gitlab
end
# rubocop: enable CodeReuse/ActiveRecord
+ # Note: if you're going to replace `legacy_bulk_insert` with something that triggers callback
+ # to generate HTML version - you also need to regenerate it in
+ # Gitlab::GithubImport::Importer::NoteAttachmentsImporter.
def execute
bulk_insert(Release, build_releases)
end
@@ -21,21 +24,21 @@ module Gitlab
end
def already_imported?(release)
- existing_tags.include?(release.tag_name) || release.tag_name.nil?
+ existing_tags.include?(release[:tag_name]) || release[:tag_name].nil?
end
def build(release)
- existing_tags.add(release.tag_name)
+ existing_tags.add(release[:tag_name])
{
- name: release.name,
- tag: release.tag_name,
+ name: release[:name],
+ tag: release[:tag_name],
author_id: fetch_author_id(release),
description: description_for(release),
- created_at: release.created_at,
- updated_at: release.created_at,
+ created_at: release[:created_at],
+ updated_at: release[:created_at],
# Draft releases will have a null published_at
- released_at: release.published_at || Time.current,
+ released_at: release[:published_at] || Time.current,
project_id: project.id
}
end
@@ -45,7 +48,7 @@ module Gitlab
end
def description_for(release)
- release.body.presence || "Release for tag #{release.tag_name}"
+ release[:body].presence || "Release for tag #{release[:tag_name]}"
end
def object_type
diff --git a/lib/gitlab/github_import/importer/single_endpoint_issue_events_importer.rb b/lib/gitlab/github_import/importer/single_endpoint_issue_events_importer.rb
index 8a9ddfc6ec0..4090555c85e 100644
--- a/lib/gitlab/github_import/importer/single_endpoint_issue_events_importer.rb
+++ b/lib/gitlab/github_import/importer/single_endpoint_issue_events_importer.rb
@@ -22,13 +22,15 @@ module Gitlab
# To make it possible to identify issue in separated worker we need to patch
# Sawyer instances here with issue number
def each_associated(parent_record, associated)
+ associated = associated.to_h
+
compose_associated_id!(parent_record, associated)
return if already_imported?(associated)
Gitlab::GithubImport::ObjectCounter.increment(project, object_type, :fetched)
pull_request = parent_record.is_a? MergeRequest
- associated.issue = { 'number' => parent_record.iid, 'pull_request' => pull_request }
+ associated[:issue] = { number: parent_record.iid, pull_request: pull_request }
yield(associated)
mark_as_imported(associated)
@@ -78,7 +80,7 @@ module Gitlab
end
def id_for_already_imported_cache(event)
- event.id
+ event[:id]
end
def collection_options
@@ -87,9 +89,9 @@ module Gitlab
# Cross-referenced events on Github doesn't have id.
def compose_associated_id!(issuable, event)
- return if event.event != 'cross-referenced'
+ return if event[:event] != 'cross-referenced'
- event.id = "cross-reference##{issuable.iid}-in-#{event.source.issue.id}"
+ event[:id] = "cross-reference##{issuable.iid}-in-#{event.dig(:source, :issue, :id)}"
end
end
end