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:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-12-17 14:59:07 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-12-17 14:59:07 +0300
commit8b573c94895dc0ac0e1d9d59cf3e8745e8b539ca (patch)
tree544930fb309b30317ae9797a9683768705d664c4 /lib/gitlab/import_export
parent4b1de649d0168371549608993deac953eb692019 (diff)
Add latest changes from gitlab-org/gitlab@13-7-stable-eev13.7.0-rc42
Diffstat (limited to 'lib/gitlab/import_export')
-rw-r--r--lib/gitlab/import_export/group/tree_restorer.rb16
-rw-r--r--lib/gitlab/import_export/import_failure_service.rb31
-rw-r--r--lib/gitlab/import_export/importer.rb5
-rw-r--r--lib/gitlab/import_export/project/import_export.yml4
-rw-r--r--lib/gitlab/import_export/project/sample/relation_tree_restorer.rb4
-rw-r--r--lib/gitlab/import_export/relation_tree_restorer.rb28
-rw-r--r--lib/gitlab/import_export/wiki_restorer.rb28
7 files changed, 61 insertions, 55 deletions
diff --git a/lib/gitlab/import_export/group/tree_restorer.rb b/lib/gitlab/import_export/group/tree_restorer.rb
index d0c0999f291..dfe27118d66 100644
--- a/lib/gitlab/import_export/group/tree_restorer.rb
+++ b/lib/gitlab/import_export/group/tree_restorer.rb
@@ -74,6 +74,12 @@ module Gitlab
group = create_group(group_attributes)
restore_group(group, group_attributes)
+ rescue => e
+ import_failure_service.log_import_failure(
+ source: 'process_child',
+ relation_key: 'group',
+ exception: e
+ )
end
def create_group(group_attributes)
@@ -83,13 +89,17 @@ module Gitlab
parent_group = @groups_mapping.fetch(parent_id) { raise(ArgumentError, 'Parent group not found') }
- ::Groups::CreateService.new(
+ group = ::Groups::CreateService.new(
user,
name: name,
path: path,
parent_id: parent_group.id,
visibility_level: sub_group_visibility_level(group_attributes.attributes, parent_group)
).execute
+
+ group.validate!
+
+ group
end
def restore_group(group, group_attributes)
@@ -134,6 +144,10 @@ module Gitlab
)
end
end
+
+ def import_failure_service
+ Gitlab::ImportExport::ImportFailureService.new(@top_level_group)
+ end
end
end
end
diff --git a/lib/gitlab/import_export/import_failure_service.rb b/lib/gitlab/import_export/import_failure_service.rb
index d4eca551b49..bf7200726a1 100644
--- a/lib/gitlab/import_export/import_failure_service.rb
+++ b/lib/gitlab/import_export/import_failure_service.rb
@@ -28,23 +28,26 @@ module Gitlab
end
def log_import_failure(source:, relation_key: nil, relation_index: nil, exception:, retry_count: 0)
- extra = {
- source: source,
- relation_key: relation_key,
+ attributes = {
relation_index: relation_index,
- retry_count: retry_count
+ source: source,
+ retry_count: retry_count,
+ importable_column_name => importable.id
}
- extra[importable_column_name] = importable.id
-
- Gitlab::ErrorTracking.track_exception(exception, extra)
-
- attributes = {
- exception_class: exception.class.to_s,
- exception_message: exception.message.truncate(255),
- correlation_id_value: Labkit::Correlation::CorrelationId.current_or_new_id
- }.merge(extra)
- ImportFailure.create(attributes)
+ Gitlab::ErrorTracking.track_exception(
+ exception,
+ attributes.merge(relation_name: relation_key)
+ )
+
+ ImportFailure.create(
+ attributes.merge(
+ exception_class: exception.class.to_s,
+ exception_message: exception.message.truncate(255),
+ correlation_id_value: Labkit::Correlation::CorrelationId.current_or_new_id,
+ relation_key: relation_key
+ )
+ )
end
private
diff --git a/lib/gitlab/import_export/importer.rb b/lib/gitlab/import_export/importer.rb
index 8e78f6e274a..789249c7d91 100644
--- a/lib/gitlab/import_export/importer.rb
+++ b/lib/gitlab/import_export/importer.rb
@@ -79,10 +79,9 @@ module Gitlab
end
def wiki_restorer
- Gitlab::ImportExport::WikiRestorer.new(path_to_bundle: wiki_repo_path,
+ Gitlab::ImportExport::RepoRestorer.new(path_to_bundle: wiki_repo_path,
shared: shared,
- project: ProjectWiki.new(project),
- wiki_enabled: project.wiki_enabled?)
+ project: ProjectWiki.new(project))
end
def design_repo_restorer
diff --git a/lib/gitlab/import_export/project/import_export.yml b/lib/gitlab/import_export/project/import_export.yml
index ae7ddbc5eba..778b42f4358 100644
--- a/lib/gitlab/import_export/project/import_export.yml
+++ b/lib/gitlab/import_export/project/import_export.yml
@@ -169,6 +169,7 @@ excluded_attributes:
- :compliance_framework_setting
- :show_default_award_emojis
- :services
+ - :exported_protected_branches
namespaces:
- :runners_token
- :runners_token_encrypted
@@ -219,6 +220,7 @@ excluded_attributes:
- :duplicated_to_id
- :promoted_to_epic_id
- :blocking_issues_count
+ - :service_desk_reply_to
merge_request:
- :milestone_id
- :sprint_id
@@ -340,10 +342,12 @@ excluded_attributes:
- :protected_environment_id
boards:
- :milestone_id
+ - :iteration_id
lists:
- :board_id
- :label_id
- :milestone_id
+ - :iteration_id
epic:
- :start_date_sourcing_milestone_id
- :due_date_sourcing_milestone_id
diff --git a/lib/gitlab/import_export/project/sample/relation_tree_restorer.rb b/lib/gitlab/import_export/project/sample/relation_tree_restorer.rb
index 44ccb67a531..4db92b12968 100644
--- a/lib/gitlab/import_export/project/sample/relation_tree_restorer.rb
+++ b/lib/gitlab/import_export/project/sample/relation_tree_restorer.rb
@@ -5,8 +5,8 @@ module Gitlab
module Project
module Sample
class RelationTreeRestorer < ImportExport::RelationTreeRestorer
- def initialize(*args)
- super
+ def initialize(...)
+ super(...)
@date_calculator = Gitlab::ImportExport::Project::Sample::DateCalculator.new(dates)
end
diff --git a/lib/gitlab/import_export/relation_tree_restorer.rb b/lib/gitlab/import_export/relation_tree_restorer.rb
index ea16d978127..8bc87ecb071 100644
--- a/lib/gitlab/import_export/relation_tree_restorer.rb
+++ b/lib/gitlab/import_export/relation_tree_restorer.rb
@@ -71,7 +71,7 @@ module Gitlab
end
def process_relation_item!(relation_key, relation_definition, relation_index, data_hash)
- relation_object = build_relation(relation_key, relation_definition, data_hash)
+ relation_object = build_relation(relation_key, relation_definition, relation_index, data_hash)
return unless relation_object
return if importable_class == ::Project && group_model?(relation_object)
@@ -139,23 +139,35 @@ module Gitlab
end
end
- def build_relations(relation_key, relation_definition, data_hashes)
+ def build_relations(relation_key, relation_definition, relation_index, data_hashes)
data_hashes
- .map { |data_hash| build_relation(relation_key, relation_definition, data_hash) }
+ .map { |data_hash| build_relation(relation_key, relation_definition, relation_index, data_hash) }
.tap { |entries| entries.compact! }
end
- def build_relation(relation_key, relation_definition, data_hash)
+ def build_relation(relation_key, relation_definition, relation_index, data_hash)
# TODO: This is hack to not create relation for the author
# Rather make `RelationFactory#set_note_author` to take care of that
return data_hash if relation_key == 'author' || already_restored?(data_hash)
# create relation objects recursively for all sub-objects
relation_definition.each do |sub_relation_key, sub_relation_definition|
- transform_sub_relations!(data_hash, sub_relation_key, sub_relation_definition)
+ transform_sub_relations!(data_hash, sub_relation_key, sub_relation_definition, relation_index)
end
- @relation_factory.create(relation_factory_params(relation_key, data_hash))
+ relation = @relation_factory.create(**relation_factory_params(relation_key, data_hash))
+
+ if relation && !relation.valid?
+ @shared.logger.warn(
+ message: "[Project/Group Import] Invalid object relation built",
+ relation_key: relation_key,
+ relation_index: relation_index,
+ relation_class: relation.class.name,
+ error_messages: relation.errors.full_messages.join(". ")
+ )
+ end
+
+ relation
end
# Since we update the data hash in place as we restore relation items,
@@ -165,7 +177,7 @@ module Gitlab
!relation_item.is_a?(Hash)
end
- def transform_sub_relations!(data_hash, sub_relation_key, sub_relation_definition)
+ def transform_sub_relations!(data_hash, sub_relation_key, sub_relation_definition, relation_index)
sub_data_hash = data_hash[sub_relation_key]
return unless sub_data_hash
@@ -176,11 +188,13 @@ module Gitlab
build_relations(
sub_relation_key,
sub_relation_definition,
+ relation_index,
sub_data_hash).presence
else
build_relation(
sub_relation_key,
sub_relation_definition,
+ relation_index,
sub_data_hash)
end
diff --git a/lib/gitlab/import_export/wiki_restorer.rb b/lib/gitlab/import_export/wiki_restorer.rb
deleted file mode 100644
index 359ba8ba769..00000000000
--- a/lib/gitlab/import_export/wiki_restorer.rb
+++ /dev/null
@@ -1,28 +0,0 @@
-# frozen_string_literal: true
-
-module Gitlab
- module ImportExport
- class WikiRestorer < RepoRestorer
- def initialize(project:, shared:, path_to_bundle:, wiki_enabled:)
- super(project: project, shared: shared, path_to_bundle: path_to_bundle)
-
- @project = project
- @wiki_enabled = wiki_enabled
- end
-
- def restore
- project.wiki if create_empty_wiki?
-
- super
- end
-
- private
-
- attr_accessor :project, :wiki_enabled
-
- def create_empty_wiki?
- !File.exist?(path_to_bundle) && wiki_enabled
- end
- end
- end
-end