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
2cc6aaec
Commit
2cc6aaec
authored
Mar 09, 2016
by
James Lopez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
WIP (broken) - playing with import stuff
parent
2dc2ce45
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
25 additions
and
21 deletions
+25
-21
app/services/projects/import_export/project_tree_restorer.rb
app/services/projects/import_export/project_tree_restorer.rb
+15
-9
app/services/projects/import_export/relation_factory.rb
app/services/projects/import_export/relation_factory.rb
+9
-1
spec/services/projects/import_export/project_tree_restorer_spec.rb
...ices/projects/import_export/project_tree_restorer_spec.rb
+1
-11
No files found.
app/services/projects/import_export/project_tree_restorer.rb
View file @
2cc6aaec
module
Projects
module
ImportExport
class
ProjectTreeRestorer
attr_reader
:
full_path
attr_reader
:
project
def
initialize
(
path:
)
def
initialize
(
path:
,
user:
user
)
@path
=
path
@user
=
user
end
#TODO deal with ID issues.
#TODO refactor this method
def
restore
json
=
IO
.
read
(
@path
)
tree_hash
=
ActiveSupport
::
JSON
.
decode
(
json
)
relation_hash
=
{}
ImportExport
.
project_tree
.
each
do
|
relation
|
next
if
tree_hash
[
relation
.
to_s
].
empty?
tree
_hash
[
relation
.
to_s
]
=
create_relation
(
relation
,
tree_hash
[
relation
.
to_s
])
relation
_hash
[
relation
.
to_s
]
=
create_relation
(
relation
,
tree_hash
[
relation
.
to_s
])
end
project
=
Project
.
new
(
tree_hash
)
project
project_params
=
tree_hash
.
delete_if
{
|
_key
,
value
|
value
.
is_a?
(
Array
)}
@project
=
::
Projects
::
CreateService
.
new
(
@user
,
project_params
).
execute
@project
.
saved?
end
private
def
create_relation
(
relation
,
tree_hash
)
Projects
::
ImportExport
::
RelationFactory
.
create
(
relation_sym:
relation
,
relation_hash:
tree_hash
[
relation
.
to_s
])
def
create_relation
(
relation
,
relation_hash_list
)
relation_hash_list
.
map
do
|
relation_hash
|
Projects
::
ImportExport
::
RelationFactory
.
create
(
relation_sym:
relation
,
relation_hash:
relation_hash
)
end
end
end
end
end
app/services/projects/import_export/relation_factory.rb
View file @
2cc6aaec
...
...
@@ -3,8 +3,12 @@ module Projects
module
RelationFactory
extend
self
def
create
(
relation_sym:
,
relation_hash
:)
OVERRIDES
=
{
snippets: :project_snippets
}
def
create
(
relation_sym
:,
relation_hash
:)
relation_sym
=
parse_relation_sym
(
relation_sym
)
klass
=
relation_class
(
relation_sym
)
relation_hash
.
delete
(
'id'
)
#screw IDs for now
klass
.
new
(
relation_hash
)
end
...
...
@@ -13,6 +17,10 @@ module Projects
def
relation_class
(
relation_sym
)
relation_sym
.
to_s
.
classify
.
constantize
end
def
parse_relation_sym
(
relation_sym
)
OVERRIDES
[
relation_sym
]
||
relation_sym
end
end
end
end
spec/services/projects/import_export/project_tree_restorer_spec.rb
View file @
2cc6aaec
...
...
@@ -4,17 +4,11 @@ describe Projects::ImportExport::ProjectTreeRestorer, services: true do
describe
:restore
do
let
(
:user
)
{
create
(
:user
)
}
let
(
:project_tree_restorer
)
{
Projects
::
ImportExport
::
ProjectTreeRestorer
.
new
(
path:
"fixtures/import_export/project.json"
)
}
before
(
:each
)
do
#allow(project_tree_restorer)
# .to receive(:full_path).and_return("fixtures/import_export/project.json")
end
let
(
:project_tree_restorer
)
{
Projects
::
ImportExport
::
ProjectTreeRestorer
.
new
(
path:
"fixtures/import_export/project.json"
,
user:
user
)
}
context
'JSON'
do
let
(
:restored_project_json
)
do
project_tree_restorer
.
restore
#project_json(project_tree_restorer.full_path)
end
it
'restores models based on JSON'
do
...
...
@@ -22,8 +16,4 @@ describe Projects::ImportExport::ProjectTreeRestorer, services: true do
end
end
end
def
project_json
JSON
.
parse
(
IO
.
read
(
"fixtures/import_export/project.json"
))
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