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
acfa0b69
Commit
acfa0b69
authored
Apr 07, 2016
by
James Lopez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
continuing to refactor config, added spec and fixed a few problems
parent
b4fe0022
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
89 additions
and
8 deletions
+89
-8
app/services/projects/import_export/import_export.yml
app/services/projects/import_export/import_export.yml
+1
-1
app/services/projects/import_export/import_export_reader.rb
app/services/projects/import_export/import_export_reader.rb
+44
-7
spec/services/projects/import_export/import_export_reader_spec.rb
...vices/projects/import_export/import_export_reader_spec.rb
+24
-0
spec/support/import_export/import_export.yml
spec/support/import_export/import_export.yml
+20
-0
No files found.
app/services/projects/import_export/import_export.yml
View file @
acfa0b69
# Class relationships to be included in the import/export
# Class relationships to be included in the
project
import/export
:project_tree:
:project_tree:
- :issues
- :issues
- :labels
- :labels
...
...
app/services/projects/import_export/import_export_reader.rb
View file @
acfa0b69
...
@@ -7,6 +7,8 @@ module Projects
...
@@ -7,6 +7,8 @@ module Projects
{
only:
atts_only
[
:project
],
include:
build_hash
(
tree
)
}
{
only:
atts_only
[
:project
],
include:
build_hash
(
tree
)
}
end
end
private
def
config
def
config
@config
||=
YAML
.
load_file
(
'app/services/projects/import_export/import_export.yml'
)
@config
||=
YAML
.
load_file
(
'app/services/projects/import_export/import_export.yml'
)
end
end
...
@@ -27,21 +29,56 @@ module Projects
...
@@ -27,21 +29,56 @@ module Projects
array
.
map
{
|
el
|
el
.
is_a?
(
Hash
)
?
process_include
(
el
)
:
el
}
array
.
map
{
|
el
|
el
.
is_a?
(
Hash
)
?
process_include
(
el
)
:
el
}
end
end
def
process_include
(
hash
)
def
process_include
(
hash
,
included_classes_hash
=
{})
included_classes_hash
=
{}
hash
.
values
.
flatten
.
each
do
|
value
|
hash
.
values
.
flatten
.
each
do
|
value
|
value
=
value
.
is_a?
(
Hash
)
?
process_include
(
hash
)
:
value
current_key
,
value
=
process_current_class
(
hash
,
included_classes_hash
,
value
)
new_hash
=
{
:include
=>
value
}
if
included_classes_hash
[
current_key
]
new_hash
.
merge!
(
check_only
(
value
))
add_class
(
current_key
,
included_classes_hash
,
value
)
included_classes_hash
[
hash
.
keys
.
first
]
=
new_hash
else
add_new_class
(
current_key
,
included_classes_hash
,
value
)
end
end
end
included_classes_hash
included_classes_hash
end
end
def
process_current_class
(
hash
,
included_classes_hash
,
value
)
value
=
value
.
is_a?
(
Hash
)
?
process_include
(
hash
,
included_classes_hash
)
:
value
current_key
=
hash
.
keys
.
first
current_key_only
=
check_only_and_except
(
current_key
)
included_classes_hash
[
current_key
]
||=
current_key_only
unless
current_key_only
.
empty?
return
current_key
,
value
end
def
add_new_class
(
current_key
,
included_classes_hash
,
value
)
new_hash
=
{
:include
=>
value
}
new_hash
.
merge!
(
check_only_and_except
(
value
))
included_classes_hash
[
current_key
]
=
new_hash
end
def
add_class
(
current_key
,
included_classes_hash
,
value
)
check_only_hash
=
check_only_and_except
(
value
)
value
=
{
value
=>
check_only_hash
}
unless
check_only_hash
.
empty?
old_values
=
included_classes_hash
[
current_key
][
:include
]
included_classes_hash
[
current_key
][
:include
]
=
([
old_values
]
+
[
value
]).
compact
.
flatten
end
def
check_only_and_except
(
value
)
check_only
(
value
).
merge
(
check_except
(
value
))
end
def
check_only
(
value
)
def
check_only
(
value
)
key
=
value
.
is_a?
(
Hash
)
?
value
.
keys
.
first
:
value
key
=
key_from_hash
(
value
)
atts_only
[
key
].
nil?
?
{}
:
{
only:
atts_only
[
key
]
}
atts_only
[
key
].
nil?
?
{}
:
{
only:
atts_only
[
key
]
}
end
end
def
check_except
(
value
)
key
=
key_from_hash
(
value
)
atts_except
[
key
].
nil?
?
{}
:
{
except:
atts_except
[
key
]
}
end
def
key_from_hash
(
value
)
value
.
is_a?
(
Hash
)
?
value
.
keys
.
first
:
value
end
end
end
end
end
end
end
\ No newline at end of file
spec/services/projects/import_export/import_export_reader_spec.rb
0 → 100644
View file @
acfa0b69
require
'rspec'
describe
Projects
::
ImportExport
::
ImportExportReader
do
let
(
:test_config
)
{
'spec/support/import_export/import_export.yml'
}
let
(
:project_tree_hash
)
do
{
:only
=>
[
:name
,
:path
],
:include
=>
[
:issues
,
:labels
,
{
:merge_requests
=>
{
:only
=>
[
:id
],
:except
=>
[
:iid
],
:include
=>
[
:merge_request_diff
,
:merge_request_test
]
}
},
{
:commit_statuses
=>
{
:include
=>
:commit
}
}]
}
end
it
'should generate hash from project tree config'
do
allow
(
described_class
).
to
receive
(
:config
).
and_return
(
YAML
.
load_file
(
test_config
))
expect
(
described_class
.
project_tree
).
to
eq
(
project_tree_hash
)
end
end
\ No newline at end of file
spec/support/import_export/import_export.yml
0 → 100644
View file @
acfa0b69
# Class relationships to be included in the project import/export
:project_tree:
- :issues
- :labels
- :merge_requests:
- :merge_request_diff
- :merge_request_test
- :commit_statuses:
- :commit
:attributes_only:
:project:
- :name
- :path
:merge_requests:
- :id
:attributes_except:
:merge_requests:
- :iid
\ No newline at end of file
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