Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
825c68e2
Commit
825c68e2
authored
Jun 19, 2018
by
James Lopez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix some edge cases
parent
a19e08fe
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
20 additions
and
12 deletions
+20
-12
lib/gitlab/import_export/project_tree_restorer.rb
lib/gitlab/import_export/project_tree_restorer.rb
+11
-9
lib/gitlab/import_export/relation_factory.rb
lib/gitlab/import_export/relation_factory.rb
+7
-2
spec/lib/gitlab/import_export/project_tree_restorer_spec.rb
spec/lib/gitlab/import_export/project_tree_restorer_spec.rb
+2
-1
No files found.
lib/gitlab/import_export/project_tree_restorer.rb
View file @
825c68e2
module
Gitlab
module
ImportExport
class
ProjectTreeRestorer
# Relations which cannot
have both group_id and project_id at the same time
RESTRICT_PROJECT_AND_GROUP
=
%i(milestone milestones)
.
freeze
# Relations which cannot
be saved at project level
GROUP_MODELS
=
[
GroupLabel
,
Milestone
]
.
freeze
def
initialize
(
user
:,
shared
:,
project
:)
@path
=
File
.
join
(
shared
.
export_path
,
'project.json'
)
...
...
@@ -70,12 +70,20 @@ module Gitlab
def
save_relation_hash
(
relation_hash_batch
,
relation_key
)
relation_hash
=
create_relation
(
relation_key
,
relation_hash_batch
)
remove_group_models
(
relation_hash
)
if
relation_hash
.
is_a?
(
Array
)
@saved
=
false
unless
restored_project
.
append_or_update_attribute
(
relation_key
,
relation_hash
)
# Restore the project again, extra query that skips holding the AR objects in memory
@restored_project
=
Project
.
find
(
@project_id
)
end
def
remove_group_models
(
relation_hash
)
relation_hash
.
reject!
do
|
value
|
value
.
respond_to?
(
:group_id
)
&&
value
.
group_id
&&
GROUP_MODELS
.
include?
(
value
.
class
)
end
end
def
default_relation_list
reader
.
tree
.
reject
do
|
model
|
model
.
is_a?
(
Hash
)
&&
model
[
:project_members
]
...
...
@@ -181,13 +189,7 @@ module Gitlab
end
def
parsed_relation_hash
(
relation_hash
,
relation_type
)
if
RESTRICT_PROJECT_AND_GROUP
.
include?
(
relation_type
)
params
=
{}
params
[
'group_id'
]
=
restored_project
.
group
.
try
(
:id
)
if
relation_hash
[
'group_id'
]
params
[
'project_id'
]
=
restored_project
.
id
if
relation_hash
[
'project_id'
]
else
params
=
{
'group_id'
=>
restored_project
.
group
.
try
(
:id
),
'project_id'
=>
restored_project
.
id
}
end
params
=
{
'group_id'
=>
restored_project
.
group
.
try
(
:id
),
'project_id'
=>
restored_project
.
id
}
relation_hash
.
merge
(
params
)
end
...
...
lib/gitlab/import_export/relation_factory.rb
View file @
825c68e2
...
...
@@ -285,9 +285,14 @@ module Gitlab
label
.
save!
label
else
parsed_relation_hash
.
delete
(
'type'
)
if
milestone?
object
=
GroupProjectFinder
.
find_or_create
(
relation_class
,
finder_hash
)
GroupProjectFinder
.
find_or_create
(
relation_class
,
finder_hash
)
if
milestone?
parsed_relation_hash
.
delete
(
'group_id'
)
if
object
.
project_id
parsed_relation_hash
.
delete
(
'project_id'
)
if
object
.
group_id
end
object
end
end
...
...
spec/lib/gitlab/import_export/project_tree_restorer_spec.rb
View file @
825c68e2
...
...
@@ -400,7 +400,8 @@ describe Gitlab::ImportExport::ProjectTreeRestorer do
restored_project_json
expect
(
project
.
milestones
.
count
).
to
eq
(
1
)
expect
(
project
.
group
.
milestones
.
count
).
to
eq
(
1
)
expect
(
project
.
milestones
.
count
).
to
eq
(
0
)
end
end
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment