BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
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
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
15 deletions
+25
-15
import_export.yml
app/services/projects/import_export/import_export.yml
+4
-1
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
:
:project_tree
:
-
:issues
-
:issues
-
:labels
-
:labels
...
@@ -13,6 +13,7 @@
...
@@ -13,6 +13,7 @@
-
:commit_statuses
:
-
:commit_statuses
:
-
:commit
-
:commit
# Only include the following attributes for the models specified.
:attributes_only
:
:attributes_only
:
:project
:
:project
:
-
:name
-
:name
...
@@ -30,6 +31,7 @@
...
@@ -30,6 +31,7 @@
-
:email
-
:email
-
:username
-
:username
# Do not include the following attributes for the models specified.
:attributes_except
:
:attributes_except
:
:snippets
:
:snippets
:
-
:expired_at
-
: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
...
@@ -11,29 +11,25 @@ module Projects
def
restore
def
restore
json
=
IO
.
read
(
@path
)
json
=
IO
.
read
(
@path
)
@tree_hash
=
ActiveSupport
::
JSON
.
decode
(
json
)
@tree_hash
=
ActiveSupport
::
JSON
.
decode
(
json
)
@project_members
=
@tree_hash
.
delete
(
'project_members'
)
create_relations
create_relations
puts
project
.
inspect
end
end
private
private
def
members_map
def
members_map
@members
||=
Projects
::
ImportExport
::
MembersMapper
.
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
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
)
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
|
relation_list
.
each
do
|
relation
|
if
relation
.
is_a?
(
Hash
)
if
relation
.
is_a?
(
Hash
)
relation
.
values
.
each
do
|
value
|
create_sub_relations
(
relation
,
tree_hash
)
create_relations
(
value
,
@tree_hash
[
relation
.
to_s
])
end
end
end
relation_hash
=
create_relation
(
relation
,
tree_hash
[
relation
.
to_s
])
relation_key
=
relation
.
is_a?
(
Hash
)
?
relation
.
keys
.
first
:
relation
project
.
update_attribute
(
relation
,
relation_hash
)
relation_hash
=
create_relation
(
relation_key
,
tree_hash
[
relation_key
.
to_s
])
project
.
update_attribute
(
relation_key
,
relation_hash
)
# relation_hash = nil
# relation_hash = nil
# # FIXME
# # FIXME
# # next if tree_hash[relation.to_s].blank?
# # next if tree_hash[relation.to_s].blank?
...
@@ -56,10 +52,7 @@ module Projects
...
@@ -56,10 +52,7 @@ module Projects
end
end
def
default_relation_list
def
default_relation_list
Projects
::
ImportExport
::
ImportExportReader
.
tree
Projects
::
ImportExport
::
ImportExportReader
.
tree
.
reject
{
|
model
|
model
.
is_a?
(
Hash
)
&&
model
[
:project_members
]
}
# ImportExport.project_tree.reject do |rel|
# rel.is_a?(Hash) && !rel[:project_members].blank?
# end
end
end
def
project
def
project
...
@@ -74,6 +67,20 @@ module Projects
...
@@ -74,6 +67,20 @@ module Projects
project
project
end
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
)
def
create_relation
(
relation
,
relation_hash_list
)
[
relation_hash_list
].
flatten
.
map
do
|
relation_hash
|
[
relation_hash_list
].
flatten
.
map
do
|
relation_hash
|
Projects
::
ImportExport
::
RelationFactory
.
create
(
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