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
0
Merge Requests
0
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
Léo-Paul Géneau
gitlab-ce
Commits
a59ba217
Commit
a59ba217
authored
Mar 14, 2016
by
James Lopez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
WIP - building up import tree with sub relations, etc
parent
25e078c1
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
7 deletions
+34
-7
app/services/projects/import_export.rb
app/services/projects/import_export.rb
+4
-0
app/services/projects/import_export/project_tree_restorer.rb
app/services/projects/import_export/project_tree_restorer.rb
+29
-6
fixtures/import_export/project.json
fixtures/import_export/project.json
+1
-1
No files found.
app/services/projects/import_export.rb
View file @
a59ba217
...
...
@@ -10,6 +10,10 @@ module Projects
%i(name path description issues_enabled wall_enabled merge_requests_enabled wiki_enabled snippets_enabled visibility_level archived)
end
def
project_tree_list
project_tree
.
map
{
|
r
|
r
.
is_a?
(
Hash
)
?
r
.
keys
.
first
:
r
}
end
def
project_tree
%i(issues labels milestones snippets releases events)
+
[
members
,
merge_requests
,
commit_statuses
]
end
...
...
app/services/projects/import_export/project_tree_restorer.rb
View file @
a59ba217
...
...
@@ -12,6 +12,7 @@ module Projects
json
=
IO
.
read
(
@path
)
@tree_hash
=
ActiveSupport
::
JSON
.
decode
(
json
)
create_relations
puts
project
.
inspect
end
private
...
...
@@ -21,11 +22,33 @@ module Projects
exported_members:
@tree_hash
.
delete
(
'project_members'
),
user:
@user
,
project_id:
project
.
id
)
end
def
create_relations
(
ImportExport
.
project_tree
-
[
:project_members
]).
each
do
|
relation
|
next
if
@tree_hash
[
relation
.
to_s
].
empty?
relation_hash
=
create_relation
(
relation
,
@tree_hash
[
relation
.
to_s
])
project
.
update_attribute
(
relation
,
relation_hash
)
#TODO Definitely refactor this method!
def
create_relations
(
relation_list
=
default_relation_list
,
tree_hash
=
@tree_hash
)
relation_list
.
each
do
|
relation
|
relation_hash
=
nil
# FIXME
# next if tree_hash[relation.to_s].blank?
if
(
relation
.
is_a?
(
Hash
)
&&
relation
.
values
.
first
[
:include
])
#TODO name stuff properly
relation_sym
=
relation
.
keys
.
first
#TODO remove sub-relation hashes from here so we can save the parent relation first
relation_hash
=
create_relation
(
relation_sym
,
tree_hash
[
relation_sym
.
to_s
])
sub_relations
=
[]
sub_relation
=
relation
.
values
.
first
[
:include
]
sub_relation_hash_list
=
tree_hash
[
relation
.
keys
.
first
.
to_s
]
sub_relation_hash_list
.
each
do
|
sub_relation_hash
|
sub_relations
<<
create_relation
(
relation
,
sub_relation_hash
[
relation
.
to_s
])
end
relation_hash
.
update_attribute
(
sub_relation
,
sub_relations
)
end
relation_hash
||=
create_relation
(
relation
,
tree_hash
[
relation
.
to_s
])
project
.
update_attribute
(
relation
,
relation_hash
)
end
end
def
default_relation_list
ImportExport
.
project_tree
.
reject
do
|
rel
|
rel
.
is_a?
(
Hash
)
&&
!
rel
[
:project_members
].
blank?
end
end
...
...
@@ -42,7 +65,7 @@ module Projects
end
def
create_relation
(
relation
,
relation_hash_list
)
relation_hash_list
.
map
do
|
relation_hash
|
[
relation_hash_list
].
flatten
.
map
do
|
relation_hash
|
Projects
::
ImportExport
::
RelationFactory
.
create
(
relation_sym:
relation
,
relation_hash:
relation_hash
.
merge
(
'project_id'
=>
project
.
id
),
members_map:
members_map
)
end
...
...
fixtures/import_export/project.json
View file @
a59ba217
This diff is collapsed.
Click to expand it.
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