summaryrefslogtreecommitdiff
path: root/lib/bulk_imports
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2023-02-20 13:49:51 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2023-02-20 13:49:51 +0000
commit71786ddc8e28fbd3cb3fcc4b3ff15e5962a1c82e (patch)
tree6a2d93ef3fb2d353bb7739e4b57e6541f51cdd71 /lib/bulk_imports
parenta7253423e3403b8c08f8a161e5937e1488f5f407 (diff)
downloadgitlab-ce-15.9.0-rc42.tar.gz
Add latest changes from gitlab-org/gitlab@15-9-stable-eev15.9.0-rc42
Diffstat (limited to 'lib/bulk_imports')
-rw-r--r--lib/bulk_imports/clients/graphql.rb13
-rw-r--r--lib/bulk_imports/error.rb7
-rw-r--r--lib/bulk_imports/groups/graphql/get_projects_query.rb1
-rw-r--r--lib/bulk_imports/groups/pipelines/project_entities_pipeline.rb2
-rw-r--r--lib/bulk_imports/groups/transformers/group_attributes_transformer.rb6
-rw-r--r--lib/bulk_imports/projects/pipelines/references_pipeline.rb9
-rw-r--r--lib/bulk_imports/projects/transformers/project_attributes_transformer.rb10
-rw-r--r--lib/bulk_imports/visibility_level.rb26
8 files changed, 63 insertions, 11 deletions
diff --git a/lib/bulk_imports/clients/graphql.rb b/lib/bulk_imports/clients/graphql.rb
index a9f908a4247..e1e78f52801 100644
--- a/lib/bulk_imports/clients/graphql.rb
+++ b/lib/bulk_imports/clients/graphql.rb
@@ -16,8 +16,15 @@ module BulkImports
}.to_json
)
+ unless response.success?
+ raise ::BulkImports::NetworkError.new(
+ "Unsuccessful response #{response.code} from #{response.request.path.path}",
+ response: response
+ )
+ end
+
::Gitlab::Json.parse(response.body)
- rescue *Gitlab::HTTP::HTTP_ERRORS => e
+ rescue *Gitlab::HTTP::HTTP_ERRORS, JSON::ParserError => e
raise ::BulkImports::NetworkError, e
end
end
@@ -34,10 +41,10 @@ module BulkImports
@compatible_instance_version = false
end
- def execute(*args)
+ def execute(...)
validate_instance_version!
- client.execute(*args)
+ client.execute(...)
end
def options(extra = {})
diff --git a/lib/bulk_imports/error.rb b/lib/bulk_imports/error.rb
index 38f26028276..4699d5eab5f 100644
--- a/lib/bulk_imports/error.rb
+++ b/lib/bulk_imports/error.rb
@@ -3,7 +3,8 @@
module BulkImports
class Error < StandardError
def self.unsupported_gitlab_version
- self.new("Unsupported GitLab Version. Minimum Supported Gitlab Version #{BulkImport::MIN_MAJOR_VERSION}.")
+ self.new("Unsupported GitLab version. Source instance must run GitLab version #{BulkImport::MIN_MAJOR_VERSION} " \
+ "or later.")
end
def self.scope_validation_failure
@@ -14,5 +15,9 @@ module BulkImports
def self.invalid_url
self.new("Import aborted as it was not possible to connect to the provided GitLab instance URL.")
end
+
+ def self.destination_full_path_validation_failure(full_path)
+ self.new("Import aborted as '#{full_path}' already exists. Change the destination and try again.")
+ end
end
end
diff --git a/lib/bulk_imports/groups/graphql/get_projects_query.rb b/lib/bulk_imports/groups/graphql/get_projects_query.rb
index 4784baf225c..01d2d9776ec 100644
--- a/lib/bulk_imports/groups/graphql/get_projects_query.rb
+++ b/lib/bulk_imports/groups/graphql/get_projects_query.rb
@@ -22,6 +22,7 @@ module BulkImports
nodes {
id
name
+ path
full_path: fullPath
}
}
diff --git a/lib/bulk_imports/groups/pipelines/project_entities_pipeline.rb b/lib/bulk_imports/groups/pipelines/project_entities_pipeline.rb
index 026b2e55713..7d9d8120e6c 100644
--- a/lib/bulk_imports/groups/pipelines/project_entities_pipeline.rb
+++ b/lib/bulk_imports/groups/pipelines/project_entities_pipeline.rb
@@ -13,7 +13,7 @@ module BulkImports
{
source_type: :project_entity,
source_full_path: data['full_path'],
- destination_name: data['name'],
+ destination_name: data['path'],
destination_namespace: context.entity.group.full_path,
parent_id: context.entity.id,
source_xid: GlobalID.parse(data['id']).model_id
diff --git a/lib/bulk_imports/groups/transformers/group_attributes_transformer.rb b/lib/bulk_imports/groups/transformers/group_attributes_transformer.rb
index 83b442458dc..19993629ff5 100644
--- a/lib/bulk_imports/groups/transformers/group_attributes_transformer.rb
+++ b/lib/bulk_imports/groups/transformers/group_attributes_transformer.rb
@@ -4,6 +4,8 @@ module BulkImports
module Groups
module Transformers
class GroupAttributesTransformer
+ include BulkImports::VisibilityLevel
+
# rubocop: disable Style/IfUnlessModifier
def transform(context, data)
import_entity = context.entity
@@ -49,10 +51,10 @@ module BulkImports
end
if data.has_key?('visibility')
- params['visibility_level'] = Gitlab::VisibilityLevel.string_options[data['visibility']]
+ params['visibility_level'] = visibility_level(import_entity, namespace, data['visibility'])
end
- params
+ params.with_indifferent_access
end
# rubocop: enable Style/IfUnlessModifier
diff --git a/lib/bulk_imports/projects/pipelines/references_pipeline.rb b/lib/bulk_imports/projects/pipelines/references_pipeline.rb
index 9c76f96c7be..8f44f3ffe6a 100644
--- a/lib/bulk_imports/projects/pipelines/references_pipeline.rb
+++ b/lib/bulk_imports/projects/pipelines/references_pipeline.rb
@@ -12,6 +12,8 @@ module BulkImports
data = Enumerator.new do |enum|
add_matching_objects(portable.issues, enum)
add_matching_objects(portable.merge_requests, enum)
+ add_notes(portable.issues, enum)
+ add_notes(portable.merge_requests, enum)
end
BulkImports::Pipeline::ExtractedData.new(data: data)
@@ -39,9 +41,16 @@ module BulkImports
collection.each_batch(of: BATCH_SIZE, column: :iid) do |batch|
batch.each do |object|
enum << object if object_has_reference?(object)
+ end
+ end
+ end
+ def add_notes(collection, enum)
+ collection.each_batch(of: BATCH_SIZE, column: :iid) do |batch|
+ batch.each do |object|
object.notes.each_batch(of: BATCH_SIZE) do |notes_batch|
notes_batch.each do |note|
+ note.refresh_markdown_cache!
enum << note if object_has_reference?(note)
end
end
diff --git a/lib/bulk_imports/projects/transformers/project_attributes_transformer.rb b/lib/bulk_imports/projects/transformers/project_attributes_transformer.rb
index 205c3185f72..c5ed9d42e44 100644
--- a/lib/bulk_imports/projects/transformers/project_attributes_transformer.rb
+++ b/lib/bulk_imports/projects/transformers/project_attributes_transformer.rb
@@ -4,21 +4,23 @@ module BulkImports
module Projects
module Transformers
class ProjectAttributesTransformer
+ include BulkImports::VisibilityLevel
+
PROJECT_IMPORT_TYPE = 'gitlab_project_migration'
def transform(context, data)
project = {}
entity = context.entity
- visibility = data.delete('visibility')
+ namespace = Namespace.find_by_full_path(entity.destination_namespace)
project[:name] = entity.destination_slug
project[:path] = entity.destination_slug.parameterize
project[:created_at] = data['created_at']
project[:import_type] = PROJECT_IMPORT_TYPE
- project[:visibility_level] = Gitlab::VisibilityLevel.string_options[visibility] if visibility.present?
- project[:namespace_id] = Namespace.find_by_full_path(entity.destination_namespace)&.id if entity.destination_namespace.present?
+ project[:visibility_level] = visibility_level(entity, namespace, data['visibility'])
+ project[:namespace_id] = namespace.id if namespace
- project
+ project.with_indifferent_access
end
end
end
diff --git a/lib/bulk_imports/visibility_level.rb b/lib/bulk_imports/visibility_level.rb
new file mode 100644
index 00000000000..6b0af15dd7b
--- /dev/null
+++ b/lib/bulk_imports/visibility_level.rb
@@ -0,0 +1,26 @@
+# frozen_string_literal: true
+
+module BulkImports
+ module VisibilityLevel
+ private
+
+ def visibility_level(entity, namespace, visibility_string)
+ requested = requested_visibility_level(entity, visibility_string)
+ max_allowed = max_allowed_visibility_level(namespace)
+
+ return requested if max_allowed >= requested
+
+ max_allowed
+ end
+
+ def requested_visibility_level(entity, visibility_string)
+ Gitlab::VisibilityLevel.string_options[visibility_string] || entity.default_visibility_level
+ end
+
+ def max_allowed_visibility_level(namespace)
+ return Gitlab::VisibilityLevel.allowed_levels.max if namespace.blank?
+
+ Gitlab::VisibilityLevel.closest_allowed_level(namespace.visibility_level)
+ end
+ end
+end