Commit 7aff1f63 authored by James Lopez's avatar James Lopez

Merge branch 'if-195888-import_to_find_group_objects_within_all_group_ancestors' into 'master'

Search group-level objects among all ancestors during import

See merge request gitlab-org/gitlab!24079
parents 2ce5ef22 f6a56867
---
title: Search group-level objects among all ancestors during project import
merge_request:
author:
type: changed
...@@ -24,7 +24,7 @@ describe Gitlab::ImportExport::ProjectTreeRestorer do ...@@ -24,7 +24,7 @@ describe Gitlab::ImportExport::ProjectTreeRestorer do
:issues_disabled, :issues_disabled,
name: 'project', name: 'project',
path: 'project', path: 'project',
group: create(:group, visibility_level: Gitlab::VisibilityLevel::PRIVATE)) group: create(:group, :private))
end end
context 'with pre-existing epic' do context 'with pre-existing epic' do
......
# frozen_string_literal: true
require 'spec_helper'
describe Gitlab::ImportExport::GroupProjectObjectBuilder do
let!(:group) { create(:group, :private) }
let!(:subgroup) { create(:group, :private, parent: group) }
let!(:project) do
create(:project, :repository,
:builds_disabled,
:issues_disabled,
name: 'project',
path: 'project',
group: subgroup)
end
context 'epics' do
it 'finds the existing epic' do
epic = create(:epic, title: 'epic', group: project.group)
expect(described_class.build(Epic,
'iid' => 1,
'title' => 'epic',
'group' => project.group,
'author_id' => project.creator.id)).to eq(epic)
end
it 'finds the existing epic in root ancestor' do
epic = create(:epic, title: 'epic', group: group)
expect(described_class.build(Epic,
'iid' => 1,
'title' => 'epic',
'group' => project.group,
'author_id' => project.creator.id)).to eq(epic)
end
it 'creates a new epic' do
epic = described_class.build(Epic,
'iid' => 1,
'title' => 'epic',
'group' => project.group,
'author_id' => project.creator.id)
expect(epic.persisted?).to be true
end
end
end
...@@ -50,7 +50,7 @@ module Gitlab ...@@ -50,7 +50,7 @@ module Gitlab
def where_clause_base def where_clause_base
[].tap do |clauses| [].tap do |clauses|
clauses << table[:project_id].eq(project.id) if project clauses << table[:project_id].eq(project.id) if project
clauses << table[:group_id].eq(group.id) if group clauses << table[:group_id].in(group.self_and_ancestors_ids) if group
end.reduce(:or) end.reduce(:or)
end end
...@@ -60,7 +60,9 @@ module Gitlab ...@@ -60,7 +60,9 @@ module Gitlab
end end
def prepare_attributes def prepare_attributes
attributes.except('group').tap do |atts| attributes.dup.tap do |atts|
atts.delete('group') unless epic?
if label? if label?
atts['type'] = 'ProjectLabel' # Always create project labels atts['type'] = 'ProjectLabel' # Always create project labels
elsif milestone? elsif milestone?
......
...@@ -3,13 +3,15 @@ ...@@ -3,13 +3,15 @@
require 'spec_helper' require 'spec_helper'
describe Gitlab::ImportExport::GroupProjectObjectBuilder do describe Gitlab::ImportExport::GroupProjectObjectBuilder do
let(:project) do let!(:group) { create(:group, :private) }
let!(:subgroup) { create(:group, :private, parent: group) }
let!(:project) do
create(:project, :repository, create(:project, :repository,
:builds_disabled, :builds_disabled,
:issues_disabled, :issues_disabled,
name: 'project', name: 'project',
path: 'project', path: 'project',
group: create(:group)) group: subgroup)
end end
let(:lru_cache) { subject.send(:lru_cache) } let(:lru_cache) { subject.send(:lru_cache) }
...@@ -75,6 +77,15 @@ describe Gitlab::ImportExport::GroupProjectObjectBuilder do ...@@ -75,6 +77,15 @@ describe Gitlab::ImportExport::GroupProjectObjectBuilder do
'group' => project.group)).to eq(group_label) 'group' => project.group)).to eq(group_label)
end end
it 'finds the existing group label in root ancestor' do
group_label = create(:group_label, name: 'group label', group: group)
expect(described_class.build(Label,
'title' => 'group label',
'project' => project,
'group' => group)).to eq(group_label)
end
it 'creates a new label' do it 'creates a new label' do
label = described_class.build(Label, label = described_class.build(Label,
'title' => 'group label', 'title' => 'group label',
...@@ -95,6 +106,15 @@ describe Gitlab::ImportExport::GroupProjectObjectBuilder do ...@@ -95,6 +106,15 @@ describe Gitlab::ImportExport::GroupProjectObjectBuilder do
'group' => project.group)).to eq(milestone) 'group' => project.group)).to eq(milestone)
end end
it 'finds the existing group milestone in root ancestor' do
milestone = create(:milestone, name: 'group milestone', group: group)
expect(described_class.build(Milestone,
'title' => 'group milestone',
'project' => project,
'group' => group)).to eq(milestone)
end
it 'creates a new milestone' do it 'creates a new milestone' do
milestone = described_class.build(Milestone, milestone = described_class.build(Milestone,
'title' => 'group milestone', 'title' => 'group milestone',
......
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