Commit 1a2ed3d4 authored by Francisco Javier López's avatar Francisco Javier López Committed by Stan Hu

Remove temporal fix for import/export

parent fd486c93
...@@ -43,12 +43,11 @@ module Gitlab ...@@ -43,12 +43,11 @@ module Gitlab
relation_name.to_s.constantize relation_name.to_s.constantize
end end
def initialize(relation_sym:, relation_hash:, members_mapper:, object_builder:, merge_requests_mapping: nil, user:, importable:, excluded_keys: []) def initialize(relation_sym:, relation_hash:, members_mapper:, object_builder:, user:, importable:, excluded_keys: [])
@relation_name = self.class.overrides[relation_sym]&.to_sym || relation_sym @relation_name = self.class.overrides[relation_sym]&.to_sym || relation_sym
@relation_hash = relation_hash.except('noteable_id') @relation_hash = relation_hash.except('noteable_id')
@members_mapper = members_mapper @members_mapper = members_mapper
@object_builder = object_builder @object_builder = object_builder
@merge_requests_mapping = merge_requests_mapping
@user = user @user = user
@importable = importable @importable = importable
@imported_object_retries = 0 @imported_object_retries = 0
......
...@@ -111,28 +111,6 @@ module Gitlab ...@@ -111,28 +111,6 @@ module Gitlab
@relation_hash['group_id'] = @importable.namespace_id @relation_hash['group_id'] = @importable.namespace_id
end end
# This code is a workaround for broken project exports that don't
# export merge requests with CI pipelines (i.e. exports that were
# generated from
# https://gitlab.com/gitlab-org/gitlab/merge_requests/17844).
# This method can be removed in GitLab 12.6.
def update_merge_request_references
# If a merge request was properly created, we don't need to fix
# up this export.
return if @relation_hash['merge_request']
merge_request_id = @relation_hash['merge_request_id']
return unless merge_request_id
new_merge_request_id = @merge_requests_mapping[merge_request_id]
return unless new_merge_request_id
@relation_hash['merge_request_id'] = new_merge_request_id
parsed_relation_hash['merge_request_id'] = new_merge_request_id
end
def setup_build def setup_build
@relation_hash.delete('trace') # old export files have trace @relation_hash.delete('trace') # old export files have trace
@relation_hash.delete('token') @relation_hash.delete('token')
...@@ -147,8 +125,6 @@ module Gitlab ...@@ -147,8 +125,6 @@ module Gitlab
end end
def setup_pipeline def setup_pipeline
update_merge_request_references
@relation_hash.fetch('stages', []).each do |stage| @relation_hash.fetch('stages', []).each do |stage|
stage.statuses.each do |status| stage.statuses.each do |status|
status.pipeline = imported_object status.pipeline = imported_object
......
...@@ -76,8 +76,6 @@ module Gitlab ...@@ -76,8 +76,6 @@ module Gitlab
import_failure_service.with_retry(action: 'relation_object.save!', relation_key: relation_key, relation_index: relation_index) do import_failure_service.with_retry(action: 'relation_object.save!', relation_key: relation_key, relation_index: relation_index) do
relation_object.save! relation_object.save!
end end
save_id_mapping(relation_key, data_hash, relation_object)
rescue => e rescue => e
import_failure_service.log_import_failure( import_failure_service.log_import_failure(
source: 'process_relation_item!', source: 'process_relation_item!',
...@@ -90,17 +88,6 @@ module Gitlab ...@@ -90,17 +88,6 @@ module Gitlab
@import_failure_service ||= ImportFailureService.new(@importable) @import_failure_service ||= ImportFailureService.new(@importable)
end end
# Older, serialized CI pipeline exports may only have a
# merge_request_id and not the full hash of the merge request. To
# import these pipelines, we need to preserve the mapping between
# the old and new the merge request ID.
def save_id_mapping(relation_key, data_hash, relation_object)
return unless importable_class == Project
return unless relation_key == 'merge_requests'
merge_requests_mapping[data_hash['id']] = relation_object.id
end
def relations def relations
@relations ||= @relations ||=
@reader @reader
...@@ -219,13 +206,8 @@ module Gitlab ...@@ -219,13 +206,8 @@ module Gitlab
importable_class.to_s.downcase.to_sym importable_class.to_s.downcase.to_sym
end end
# A Hash of the imported merge request ID -> imported ID.
def merge_requests_mapping
@merge_requests_mapping ||= {}
end
def relation_factory_params(relation_key, data_hash) def relation_factory_params(relation_key, data_hash)
base_params = { {
relation_sym: relation_key.to_sym, relation_sym: relation_key.to_sym,
relation_hash: data_hash, relation_hash: data_hash,
importable: @importable, importable: @importable,
...@@ -234,9 +216,6 @@ module Gitlab ...@@ -234,9 +216,6 @@ module Gitlab
user: @user, user: @user,
excluded_keys: excluded_keys_for_relation(relation_key) excluded_keys: excluded_keys_for_relation(relation_key)
} }
base_params[:merge_requests_mapping] = merge_requests_mapping if importable_class == Project
base_params
end end
end end
end end
......
...@@ -7,7 +7,6 @@ describe Gitlab::ImportExport::BaseRelationFactory do ...@@ -7,7 +7,6 @@ describe Gitlab::ImportExport::BaseRelationFactory do
let(:project) { create(:project) } let(:project) { create(:project) }
let(:members_mapper) { double('members_mapper').as_null_object } let(:members_mapper) { double('members_mapper').as_null_object }
let(:relation_sym) { :project_snippets } let(:relation_sym) { :project_snippets }
let(:merge_requests_mapping) { {} }
let(:relation_hash) { {} } let(:relation_hash) { {} }
let(:excluded_keys) { [] } let(:excluded_keys) { [] }
...@@ -16,7 +15,6 @@ describe Gitlab::ImportExport::BaseRelationFactory do ...@@ -16,7 +15,6 @@ describe Gitlab::ImportExport::BaseRelationFactory do
relation_hash: relation_hash, relation_hash: relation_hash,
object_builder: Gitlab::ImportExport::GroupProjectObjectBuilder, object_builder: Gitlab::ImportExport::GroupProjectObjectBuilder,
members_mapper: members_mapper, members_mapper: members_mapper,
merge_requests_mapping: merge_requests_mapping,
user: user, user: user,
importable: project, importable: project,
excluded_keys: excluded_keys) excluded_keys: excluded_keys)
......
...@@ -6,7 +6,6 @@ describe Gitlab::ImportExport::ProjectRelationFactory do ...@@ -6,7 +6,6 @@ describe Gitlab::ImportExport::ProjectRelationFactory do
let(:group) { create(:group) } let(:group) { create(:group) }
let(:project) { create(:project, :repository, group: group) } let(:project) { create(:project, :repository, group: group) }
let(:members_mapper) { double('members_mapper').as_null_object } let(:members_mapper) { double('members_mapper').as_null_object }
let(:merge_requests_mapping) { {} }
let(:user) { create(:admin) } let(:user) { create(:admin) }
let(:excluded_keys) { [] } let(:excluded_keys) { [] }
let(:created_object) do let(:created_object) do
...@@ -14,7 +13,6 @@ describe Gitlab::ImportExport::ProjectRelationFactory do ...@@ -14,7 +13,6 @@ describe Gitlab::ImportExport::ProjectRelationFactory do
relation_hash: relation_hash, relation_hash: relation_hash,
object_builder: Gitlab::ImportExport::GroupProjectObjectBuilder, object_builder: Gitlab::ImportExport::GroupProjectObjectBuilder,
members_mapper: members_mapper, members_mapper: members_mapper,
merge_requests_mapping: merge_requests_mapping,
user: user, user: user,
importable: project, importable: project,
excluded_keys: excluded_keys) excluded_keys: excluded_keys)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment