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
a61456e4
Commit
a61456e4
authored
May 11, 2016
by
James Lopez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactored import to use shared error stuff and fixed a few issues with recent refactorings
parent
27867f35
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
32 additions
and
25 deletions
+32
-25
app/workers/project_import_worker.rb
app/workers/project_import_worker.rb
+0
-1
lib/gitlab/import_export/import_export_reader.rb
lib/gitlab/import_export/import_export_reader.rb
+2
-0
lib/gitlab/import_export/import_service.rb
lib/gitlab/import_export/import_service.rb
+8
-11
lib/gitlab/import_export/importer.rb
lib/gitlab/import_export/importer.rb
+7
-4
lib/gitlab/import_export/project_tree_restorer.rb
lib/gitlab/import_export/project_tree_restorer.rb
+8
-5
lib/gitlab/import_export/repo_restorer.rb
lib/gitlab/import_export/repo_restorer.rb
+4
-2
lib/gitlab/import_export/shared.rb
lib/gitlab/import_export/shared.rb
+1
-1
spec/lib/gitlab/import_export/project_tree_restorer_spec.rb
spec/lib/gitlab/import_export/project_tree_restorer_spec.rb
+2
-1
No files found.
app/workers/project_import_worker.rb
View file @
a61456e4
...
@@ -13,7 +13,6 @@ class ProjectImportWorker
...
@@ -13,7 +13,6 @@ class ProjectImportWorker
project_path:
path
)
project_path:
path
)
if
project
if
project
project
.
repository
.
after_import
project
.
repository
.
after_import
project
.
import_finish
else
else
logger
.
error
(
"There was an error during the import:
#{
tmp_file
}
"
)
logger
.
error
(
"There was an error during the import:
#{
tmp_file
}
"
)
end
end
...
...
lib/gitlab/import_export/import_export_reader.rb
View file @
a61456e4
...
@@ -2,6 +2,8 @@ module Gitlab
...
@@ -2,6 +2,8 @@ module Gitlab
module
ImportExport
module
ImportExport
class
ImportExportReader
class
ImportExportReader
attr_reader
:tree
def
initialize
(
config:
'lib/gitlab/import_export/import_export.yml'
,
shared
:)
def
initialize
(
config:
'lib/gitlab/import_export/import_export.yml'
,
shared
:)
@shared
=
shared
@shared
=
shared
config_hash
=
YAML
.
load_file
(
config
).
deep_symbolize_keys
config_hash
=
YAML
.
load_file
(
config
).
deep_symbolize_keys
...
...
lib/gitlab/import_export/import_service.rb
View file @
a61456e4
...
@@ -10,12 +10,12 @@ module Gitlab
...
@@ -10,12 +10,12 @@ module Gitlab
@archive_file
=
archive_file
@archive_file
=
archive_file
@current_user
=
owner
@current_user
=
owner
@namespace
=
Namespace
.
find
(
namespace_id
)
@namespace
=
Namespace
.
find
(
namespace_id
)
@
project_path
=
project_path
@
shared
=
Gitlab
::
ImportExport
::
Shared
.
new
(
relative_path:
path_with_namespace
,
project_path:
project_path
)
end
end
def
execute
def
execute
Gitlab
::
ImportExport
::
Importer
.
import
(
archive_file:
@archive_file
,
Gitlab
::
ImportExport
::
Importer
.
import
(
archive_file:
@archive_file
,
s
torage_path:
storage_path
)
s
hared:
@shared
)
project_tree
.
project
if
[
restore_project_tree
,
restore_repo
,
restore_wiki_repo
].
all?
project_tree
.
project
if
[
restore_project_tree
,
restore_repo
,
restore_wiki_repo
].
all?
end
end
...
@@ -26,36 +26,33 @@ module Gitlab
...
@@ -26,36 +26,33 @@ module Gitlab
end
end
def
project_tree
def
project_tree
@project_tree
||=
Gitlab
::
ImportExport
::
ProjectTreeRestorer
.
new
(
path:
storage_path
,
@project_tree
||=
Gitlab
::
ImportExport
::
ProjectTreeRestorer
.
new
(
user:
@current_user
,
user:
@current_user
,
shared:
@shared
,
project_path:
@project_path
,
namespace_id:
@namespace
.
id
)
namespace_id:
@namespace
.
id
)
end
end
def
restore_repo
def
restore_repo
Gitlab
::
ImportExport
::
RepoRestorer
.
new
(
path_to_bundle:
repo_path
,
Gitlab
::
ImportExport
::
RepoRestorer
.
new
(
path_to_bundle:
repo_path
,
shared:
@shared
,
project:
project_tree
.
project
).
restore
project:
project_tree
.
project
).
restore
end
end
def
restore_wiki_repo
def
restore_wiki_repo
Gitlab
::
ImportExport
::
RepoRestorer
.
new
(
path_to_bundle:
wiki_repo_path
,
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
)).
restore
end
end
def
storage_path
@storage_path
||=
Gitlab
::
ImportExport
.
export_path
(
relative_path:
path_with_namespace
)
end
def
path_with_namespace
def
path_with_namespace
File
.
join
(
@namespace
.
path
,
@project_path
)
File
.
join
(
@namespace
.
path
,
@project_path
)
end
end
def
repo_path
def
repo_path
File
.
join
(
storage
_path
,
'project.bundle'
)
File
.
join
(
@shared
.
export
_path
,
'project.bundle'
)
end
end
def
wiki_repo_path
def
wiki_repo_path
File
.
join
(
storage
_path
,
'project.wiki.bundle'
)
File
.
join
(
@shared
.
export
_path
,
'project.wiki.bundle'
)
end
end
end
end
end
end
...
...
lib/gitlab/import_export/importer.rb
View file @
a61456e4
...
@@ -7,20 +7,23 @@ module Gitlab
...
@@ -7,20 +7,23 @@ module Gitlab
new
(
*
args
).
import
new
(
*
args
).
import
end
end
def
initialize
(
archive_file:
,
s
torage_path
:)
def
initialize
(
archive_file:
,
s
hared
:)
@archive_file
=
archive_file
@archive_file
=
archive_file
@s
torage_path
=
storage_path
@s
hared
=
shared
end
end
def
import
def
import
FileUtils
.
mkdir_p
(
@storage_path
)
FileUtils
.
mkdir_p
(
@s
hared
.
s
torage_path
)
decompress_archive
decompress_archive
rescue
=>
e
@shared
.
error
(
e
.
message
)
false
end
end
private
private
def
decompress_archive
def
decompress_archive
untar_zxf
(
archive:
@archive_file
,
dir:
@storage_path
)
untar_zxf
(
archive:
@archive_file
,
dir:
@s
hared
.
s
torage_path
)
end
end
end
end
end
end
...
...
lib/gitlab/import_export/project_tree_restorer.rb
View file @
a61456e4
...
@@ -2,11 +2,12 @@ module Gitlab
...
@@ -2,11 +2,12 @@ module Gitlab
module
ImportExport
module
ImportExport
class
ProjectTreeRestorer
class
ProjectTreeRestorer
def
initialize
(
path
:,
user
:,
project_path
:,
namespace_id
:)
def
initialize
(
user
:,
shared
:,
namespace_id
:)
@path
=
File
.
join
(
path
,
'project.json'
)
@path
=
File
.
join
(
shared
.
export_
path
,
'project.json'
)
@user
=
user
@user
=
user
@project_path
=
project_path
@project_path
=
shared
.
opts
[
:project_path
]
@namespace_id
=
namespace_id
@namespace_id
=
namespace_id
@shared
=
shared
end
end
def
restore
def
restore
...
@@ -15,7 +16,7 @@ module Gitlab
...
@@ -15,7 +16,7 @@ module Gitlab
@project_members
=
@tree_hash
.
delete
(
'project_members'
)
@project_members
=
@tree_hash
.
delete
(
'project_members'
)
create_relations
create_relations
rescue
=>
e
rescue
=>
e
# TODO: handle errors better, move them to a shared thing
@shared
.
error
(
e
.
message
)
false
false
end
end
...
@@ -44,7 +45,9 @@ module Gitlab
...
@@ -44,7 +45,9 @@ module Gitlab
end
end
def
default_relation_list
def
default_relation_list
Gitlab
::
ImportExport
::
ImportExportReader
.
tree
.
reject
{
|
model
|
model
.
is_a?
(
Hash
)
&&
model
[
:project_members
]
}
Gitlab
::
ImportExport
::
ImportExportReader
.
new
(
shared:
@shared
).
tree
.
reject
do
|
model
|
model
.
is_a?
(
Hash
)
&&
model
[
:project_members
]
end
end
end
def
create_project
def
create_project
...
...
lib/gitlab/import_export/repo_restorer.rb
View file @
a61456e4
...
@@ -3,9 +3,10 @@ module Gitlab
...
@@ -3,9 +3,10 @@ module Gitlab
class
RepoRestorer
class
RepoRestorer
include
Gitlab
::
ImportExport
::
CommandLineUtil
include
Gitlab
::
ImportExport
::
CommandLineUtil
def
initialize
(
project
:,
path_to_bundle
:)
def
initialize
(
project
:,
shared
:,
path_to_bundle
:)
@project
=
project
@project
=
project
@path_to_bundle
=
path_to_bundle
@path_to_bundle
=
path_to_bundle
@shared
=
shared
end
end
def
restore
def
restore
...
@@ -15,7 +16,8 @@ module Gitlab
...
@@ -15,7 +16,8 @@ module Gitlab
FileUtils
.
mkdir_p
(
path_to_repo
)
FileUtils
.
mkdir_p
(
path_to_repo
)
git_unbundle
(
repo_path:
path_to_repo
,
bundle_path:
@path_to_bundle
)
git_unbundle
(
repo_path:
path_to_repo
,
bundle_path:
@path_to_bundle
)
rescue
rescue
=>
e
@shared
.
error
(
e
.
message
)
false
false
end
end
...
...
lib/gitlab/import_export/shared.rb
View file @
a61456e4
...
@@ -2,7 +2,7 @@ module Gitlab
...
@@ -2,7 +2,7 @@ module Gitlab
module
ImportExport
module
ImportExport
class
Shared
class
Shared
attr_reader
:errors
attr_reader
:errors
,
:opts
def
initialize
(
opts
)
def
initialize
(
opts
)
@opts
=
opts
@opts
=
opts
...
...
spec/lib/gitlab/import_export/project_tree_restorer_spec.rb
View file @
a61456e4
...
@@ -5,7 +5,8 @@ describe Gitlab::ImportExport::ProjectTreeRestorer, services: true do
...
@@ -5,7 +5,8 @@ describe Gitlab::ImportExport::ProjectTreeRestorer, services: true do
let
(
:user
)
{
create
(
:user
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:namespace
)
{
create
(
:namespace
,
owner:
user
)
}
let
(
:namespace
)
{
create
(
:namespace
,
owner:
user
)
}
let
(
:project_tree_restorer
)
{
described_class
.
new
(
path:
Rails
.
root
.
join
(
"spec/lib/gitlab/import_export/"
),
user:
user
,
project_path:
'project'
,
namespace_id:
namespace
.
id
)
}
let
(
:shared
)
{
Gitlab
::
ImportExport
::
Shared
.
new
(
relative_path:
"../../../spec/lib/gitlab/import_export/"
,
project_path:
'path'
)
}
let
(
:project_tree_restorer
)
{
described_class
.
new
(
user:
user
,
shared:
shared
,
namespace_id:
namespace
.
id
)
}
context
'JSON'
do
context
'JSON'
do
let
(
:restored_project_json
)
do
let
(
:restored_project_json
)
do
...
...
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