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
833dc320
Commit
833dc320
authored
Jun 13, 2016
by
James Lopez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
few more changes based on feedback
parent
f4d762d7
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
26 additions
and
17 deletions
+26
-17
members_mapper.rb
lib/gitlab/import_export/members_mapper.rb
+3
-3
project_tree_restorer.rb
lib/gitlab/import_export/project_tree_restorer.rb
+18
-9
relation_factory.rb
lib/gitlab/import_export/relation_factory.rb
+4
-4
members_mapper_spec.rb
spec/lib/gitlab/import_export/members_mapper_spec.rb
+1
-1
No files found.
lib/gitlab/import_export/members_mapper.rb
View file @
833dc320
...
...
@@ -2,13 +2,13 @@ module Gitlab
module
ImportExport
class
MembersMapper
attr_reader
:
note_member_list
attr_reader
:
missing_author_ids
def
initialize
(
exported_members
:,
user
:,
project
:)
@exported_members
=
exported_members
@user
=
user
@project
=
project
@
note_member_list
=
[]
@
missing_author_ids
=
[]
# This needs to run first, as second call would be from #map
# which means project members already exist.
...
...
@@ -37,7 +37,7 @@ module Gitlab
def
missing_keys_tracking_hash
Hash
.
new
do
|
_
,
key
|
@
note_member_list
<<
key
@
missing_author_ids
<<
key
default_user_id
end
end
...
...
lib/gitlab/import_export/project_tree_restorer.rb
View file @
833dc320
...
...
@@ -67,29 +67,38 @@ module Gitlab
project
end
# Given a relation hash containing one or more models and its relationships,
# loops through each model and each object from a model type and
# and assigns its correspondent attributes hash from +tree_hash+
# Example:
# +relation_key+ issues, loops through the list of *issues* and for each individual
# issue, finds any subrelations such as notes, creates them and assign them back to the hash
def
create_sub_relations
(
relation
,
tree_hash
)
relation_key
=
relation
.
keys
.
first
.
to_s
tree_hash
[
relation_key
].
each
do
|
relation_item
|
relation
.
values
.
flatten
.
each
do
|
sub_relation
|
if
sub_relation
.
is_a?
(
Hash
)
relation_hash
=
relation_item
[
sub_relation
.
keys
.
first
.
to_s
]
sub_relation
=
sub_relation
.
keys
.
first
else
relation_hash
=
relation_item
[
sub_relation
.
to_s
]
end
relation_hash
,
sub_relation
=
assign_relation_hash
(
relation_item
,
sub_relation
)
relation_item
[
sub_relation
.
to_s
]
=
create_relation
(
sub_relation
,
relation_hash
)
unless
relation_hash
.
blank?
end
end
end
def
assign_relation_hash
(
relation_item
,
sub_relation
)
if
sub_relation
.
is_a?
(
Hash
)
relation_hash
=
relation_item
[
sub_relation
.
keys
.
first
.
to_s
]
sub_relation
=
sub_relation
.
keys
.
first
else
relation_hash
=
relation_item
[
sub_relation
.
to_s
]
end
return
relation_hash
,
sub_relation
end
def
create_relation
(
relation
,
relation_hash_list
)
relation_array
=
[
relation_hash_list
].
flatten
.
map
do
|
relation_hash
|
Gitlab
::
ImportExport
::
RelationFactory
.
create
(
relation_sym:
relation
.
to_sym
,
relation_hash:
relation_hash
.
merge
(
'project_id'
=>
project
.
id
),
members_mapper:
members_mapper
,
user
_admin:
@user
.
is_admin?
)
user
:
@user
)
end
relation_hash_list
.
is_a?
(
Array
)
?
relation_array
:
relation_array
.
first
...
...
lib/gitlab/import_export/relation_factory.rb
View file @
833dc320
...
...
@@ -16,11 +16,11 @@ module Gitlab
new
(
*
args
).
create
end
def
initialize
(
relation_sym
:,
relation_hash
:,
members_mapper
:,
user
_admin
:)
def
initialize
(
relation_sym
:,
relation_hash
:,
members_mapper
:,
user
:)
@relation_name
=
OVERRIDES
[
relation_sym
]
||
relation_sym
@relation_hash
=
relation_hash
.
except
(
'id'
,
'noteable_id'
)
@members_mapper
=
members_mapper
@user
_admin
=
user_admin
@user
=
user
end
# Creates an object from an actual model with name "relation_sym" with params from
...
...
@@ -57,7 +57,7 @@ module Gitlab
author
=
@relation_hash
.
delete
(
'author'
)
if
admin_user?
&&
@members_mapper
.
note_member_list
.
include?
(
old_author_id
)
if
admin_user?
&&
@members_mapper
.
missing_author_ids
.
include?
(
old_author_id
)
update_note_for_missing_author
(
author
[
'name'
])
end
end
...
...
@@ -119,7 +119,7 @@ module Gitlab
end
def
admin_user?
@user
_admin
@user
.
is_admin?
end
end
end
...
...
spec/lib/gitlab/import_export/members_mapper_spec.rb
View file @
833dc320
...
...
@@ -46,7 +46,7 @@ describe Gitlab::ImportExport::MembersMapper, services: true do
it
'updates missing author IDs on missing project member'
do
members_mapper
.
map
[
-
1
]
expect
(
members_mapper
.
note_member_list
.
first
).
to
eq
(
-
1
)
expect
(
members_mapper
.
missing_author_ids
.
first
).
to
eq
(
-
1
)
end
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