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
Tatuya Kamada
gitlab-ce
Commits
102074c8
Commit
102074c8
authored
Jun 02, 2016
by
James Lopez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
more and more refactoring
parent
7c8359b7
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
41 additions
and
46 deletions
+41
-46
lib/gitlab/import_export/import_service.rb
lib/gitlab/import_export/import_service.rb
+9
-13
lib/gitlab/import_export/members_mapper.rb
lib/gitlab/import_export/members_mapper.rb
+25
-24
lib/gitlab/import_export/project_tree_restorer.rb
lib/gitlab/import_export/project_tree_restorer.rb
+3
-1
lib/gitlab/import_export/relation_factory.rb
lib/gitlab/import_export/relation_factory.rb
+1
-1
lib/gitlab/import_export/uploads_saver.rb
lib/gitlab/import_export/uploads_saver.rb
+0
-4
lib/gitlab/import_export/version_checker.rb
lib/gitlab/import_export/version_checker.rb
+3
-3
No files found.
lib/gitlab/import_export/import_service.rb
View file @
102074c8
...
...
@@ -16,7 +16,7 @@ module Gitlab
def
execute
Gitlab
::
ImportExport
::
Importer
.
import
(
archive_file:
@archive_file
,
shared:
@shared
)
if
[
restore_version
,
restore_project_tree
,
restore_repo
,
restore_wiki_repo
,
restore_uploads
].
all?
if
check_version!
&&
[
project_tree
,
repo_restorer
,
wiki_restorer
,
uploads_restorer
].
all?
(
&
:restore
)
project_tree
.
project
else
project_tree
.
project
.
destroy
if
project_tree
.
project
...
...
@@ -26,12 +26,8 @@ module Gitlab
private
def
restore_version
Gitlab
::
ImportExport
::
VersionRestorer
.
restore
(
shared:
@shared
)
end
def
restore_project_tree
project_tree
.
restore
def
check_version!
Gitlab
::
ImportExport
::
VersionChecker
.
check!
(
shared:
@shared
)
end
def
project_tree
...
...
@@ -40,20 +36,20 @@ module Gitlab
namespace_id:
@namespace
.
id
)
end
def
re
store_repo
def
re
po_restorer
Gitlab
::
ImportExport
::
RepoRestorer
.
new
(
path_to_bundle:
repo_path
,
shared:
@shared
,
project:
project_tree
.
project
)
.
restore
project:
project_tree
.
project
)
end
def
restore_wiki_repo
def
wiki_restorer
Gitlab
::
ImportExport
::
RepoRestorer
.
new
(
path_to_bundle:
wiki_repo_path
,
shared:
@shared
,
project:
ProjectWiki
.
new
(
project_tree
.
project
))
.
restore
project:
ProjectWiki
.
new
(
project_tree
.
project
))
end
def
restore_uploads
Gitlab
::
ImportExport
::
UploadsRestorer
.
restore
(
project:
project_tree
.
project
,
shared:
@shared
)
def
uploads_restorer
Gitlab
::
ImportExport
::
UploadsRestorer
.
new
(
project:
project_tree
.
project
,
shared:
@shared
)
end
def
path_with_namespace
(
project_path
)
...
...
lib/gitlab/import_export/members_mapper.rb
View file @
102074c8
...
...
@@ -12,32 +12,27 @@ module Gitlab
# This needs to run first, as second call would be from generate_map
# which means project members already exist.
default_project_member
@project_member_map
=
Hash
.
new
do
|
_
,
key
|
@note_member_list
<<
key
default_project_member
ensure_default_member!
end
def
map
@map
||=
generate_map
end
def
default_project_member
@default_project_member
||=
begin
default_member
=
ProjectMember
.
new
(
default_project_member_hash
)
default_member
.
create!
default_member
.
user
.
id
end
def
default_user_id
@user
.
id
end
def
map
private
def
generate_map
@map
||=
begin
@exported_members
.
inject
(
@project_member_map
)
do
|
hash
,
member
|
@exported_members
.
inject
(
missing_keys_tracking_hash
)
do
|
hash
,
member
|
existing_user
=
User
.
where
(
find_project_user_query
(
member
)).
first
if
existing_user
old_user_id
=
member
[
'user'
][
'id'
]
add_user_as_team_member
(
existing_user
,
member
)
if
existing_user
&&
add_user_as_team_member
(
existing_user
,
member
).
persisted?
hash
[
old_user_id
]
=
existing_user
.
id
end
hash
...
...
@@ -45,21 +40,27 @@ module Gitlab
end
end
private
def
missing_keys_tracking_hash
Hash
.
new
do
|
_
,
key
|
@note_member_list
<<
key
@user
.
id
end
end
def
ensure_default_member!
ProjectMember
.
create!
(
user:
@user
,
access_level:
ProjectMember
::
MASTER
,
source_id:
@project
.
id
,
importing:
true
)
end
def
add_user_as_team_member
(
existing_user
,
member
)
member
[
'user'
]
=
existing_user
ProjectMember
.
create!
(
member_hash
(
member
))
ProjectMember
.
create
(
member_hash
(
member
))
end
def
member_hash
(
member
)
member
.
except
(
'id'
).
merge
(
source_id:
@project
.
id
,
importing:
true
)
end
def
default_project_member_hash
{
user:
@user
,
access_level:
ProjectMember
::
MASTER
,
source_id:
@project
.
id
,
importing:
true
}
end
def
find_project_user_query
(
member
)
user_arel
[
:username
].
eq
(
member
[
'user'
][
'username'
]).
or
(
user_arel
[
:email
].
eq
(
member
[
'user'
][
'email'
]))
end
...
...
lib/gitlab/import_export/project_tree_restorer.rb
View file @
102074c8
...
...
@@ -80,12 +80,14 @@ module Gitlab
end
def
create_relation
(
relation
,
relation_hash_list
)
[
relation_hash_list
].
flatten
.
map
do
|
relation_hash
|
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?
)
end
relation_hash_list
.
is_a?
(
Array
)
?
relation_array
:
relation_array
.
first
end
end
end
...
...
lib/gitlab/import_export/relation_factory.rb
View file @
102074c8
...
...
@@ -45,7 +45,7 @@ module Gitlab
if
user_admin
relation_hash
[
'author_id'
]
=
members_map
.
map
[
old_author_id
]
else
relation_hash
[
'author_id'
]
=
members_map
.
default_
project_member
relation_hash
[
'author_id'
]
=
members_map
.
default_
user_id
end
author
=
relation_hash
.
delete
(
'author'
)
...
...
lib/gitlab/import_export/uploads_saver.rb
View file @
102074c8
...
...
@@ -2,10 +2,6 @@ module Gitlab
module
ImportExport
class
UploadsSaver
def
self
.
save
(
*
args
)
new
(
*
args
).
save
end
def
initialize
(
project
:,
shared
:)
@project
=
project
@shared
=
shared
...
...
lib/gitlab/import_export/version_
restor
er.rb
→
lib/gitlab/import_export/version_
check
er.rb
View file @
102074c8
module
Gitlab
module
ImportExport
class
Version
Restor
er
class
Version
Check
er
def
self
.
restore
(
*
args
)
new
(
*
args
).
restore
new
(
*
args
).
check
end
def
initialize
(
shared
:)
@shared
=
shared
end
def
restore
def
check!
version
=
File
.
open
(
version_file
,
&
:readline
)
verify_version!
(
version
)
rescue
=>
e
...
...
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