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
Boxiang Sun
gitlab-ce
Commits
56fc5893
Commit
56fc5893
authored
Apr 11, 2016
by
James Lopez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
more refactoring to use dynamic import
parent
a28be02e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
15 deletions
+24
-15
app/services/projects/import_export/import_export.yml
app/services/projects/import_export/import_export.yml
+3
-1
app/services/projects/import_export/project_tree_restorer.rb
app/services/projects/import_export/project_tree_restorer.rb
+21
-14
No files found.
app/services/projects/import_export/import_export.yml
View file @
56fc5893
#
Class
relationships to be included in the project import/export
#
Model
relationships to be included in the project import/export
:project_tree:
- :issues
- :labels
...
...
@@ -13,6 +13,7 @@
- :commit_statuses:
- :commit
# Only include the following attributes for the models specified.
:attributes_only:
:project:
- :name
...
...
@@ -30,6 +31,7 @@
- :email
- :username
# Do not include the following attributes for the models specified.
:attributes_except:
:snippets:
- :expired_at
\ No newline at end of file
app/services/projects/import_export/project_tree_restorer.rb
View file @
56fc5893
...
...
@@ -11,29 +11,25 @@ module Projects
def
restore
json
=
IO
.
read
(
@path
)
@tree_hash
=
ActiveSupport
::
JSON
.
decode
(
json
)
@project_members
=
@tree_hash
.
delete
(
'project_members'
)
create_relations
puts
project
.
inspect
end
private
def
members_map
@members
||=
Projects
::
ImportExport
::
MembersMapper
.
map
(
exported_members:
@
tree_hash
.
delete
(
'project_members'
)
,
user:
@user
,
project_id:
project
.
id
)
exported_members:
@
project_members
,
user:
@user
,
project_id:
project
.
id
)
end
#TODO Definitely refactor this method!
#TODO Think about having a yaml file to describe the tree instead of just hashes?
def
create_relations
(
relation_list
=
default_relation_list
,
tree_hash
=
@tree_hash
)
members_map
# TODO remove this and fix project_members
relation_list
.
each
do
|
relation
|
if
relation
.
is_a?
(
Hash
)
relation
.
values
.
each
do
|
value
|
create_relations
(
value
,
@tree_hash
[
relation
.
to_s
])
end
create_sub_relations
(
relation
,
tree_hash
)
end
relation_hash
=
create_relation
(
relation
,
tree_hash
[
relation
.
to_s
])
project
.
update_attribute
(
relation
,
relation_hash
)
relation_key
=
relation
.
is_a?
(
Hash
)
?
relation
.
keys
.
first
:
relation
relation_hash
=
create_relation
(
relation_key
,
tree_hash
[
relation_key
.
to_s
])
project
.
update_attribute
(
relation_key
,
relation_hash
)
# relation_hash = nil
# # FIXME
# # next if tree_hash[relation.to_s].blank?
...
...
@@ -56,10 +52,7 @@ module Projects
end
def
default_relation_list
Projects
::
ImportExport
::
ImportExportReader
.
tree
# ImportExport.project_tree.reject do |rel|
# rel.is_a?(Hash) && !rel[:project_members].blank?
# end
Projects
::
ImportExport
::
ImportExportReader
.
tree
.
reject
{
|
model
|
model
.
is_a?
(
Hash
)
&&
model
[
:project_members
]
}
end
def
project
...
...
@@ -74,6 +67,20 @@ module Projects
project
end
def
create_sub_relations
(
relation
,
tree_hash
)
# TODO refactor this
relation_key
=
relation
.
keys
.
first
tree_hash
[
relation_key
.
to_s
].
each
do
|
relation_item
|
relation
.
values
.
each
do
|
sub_relation
|
relation_hash
=
relation_item
[
sub_relation
.
to_s
]
next
if
relation_hash
.
blank?
sub_relation_object
=
Projects
::
ImportExport
::
RelationFactory
.
create
(
relation_sym:
sub_relation
,
relation_hash:
relation_hash
,
members_map:
members_map
)
relation_item
[
sub_relation
.
to_s
]
=
sub_relation_object
end
end
end
def
create_relation
(
relation
,
relation_hash_list
)
[
relation_hash_list
].
flatten
.
map
do
|
relation_hash
|
Projects
::
ImportExport
::
RelationFactory
.
create
(
...
...
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