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