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
1
Merge Requests
1
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
nexedi
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
Hide 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
project_path:
path
)
if
project
project
.
repository
.
after_import
project
.
import_finish
else
logger
.
error
(
"There was an error during the import:
#{
tmp_file
}
"
)
end
...
...
lib/gitlab/import_export/import_export_reader.rb
View file @
a61456e4
...
...
@@ -2,6 +2,8 @@ module Gitlab
module
ImportExport
class
ImportExportReader
attr_reader
:tree
def
initialize
(
config:
'lib/gitlab/import_export/import_export.yml'
,
shared
:)
@shared
=
shared
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
@archive_file
=
archive_file
@current_user
=
owner
@namespace
=
Namespace
.
find
(
namespace_id
)
@
project_path
=
project_path
@
shared
=
Gitlab
::
ImportExport
::
Shared
.
new
(
relative_path:
path_with_namespace
,
project_path:
project_path
)
end
def
execute
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?
end
...
...
@@ -26,36 +26,33 @@ module Gitlab
end
def
project_tree
@project_tree
||=
Gitlab
::
ImportExport
::
ProjectTreeRestorer
.
new
(
path:
storage_path
,
user:
@current_user
,
project_path:
@project_path
,
@project_tree
||=
Gitlab
::
ImportExport
::
ProjectTreeRestorer
.
new
(
user:
@current_user
,
shared:
@shared
,
namespace_id:
@namespace
.
id
)
end
def
restore_repo
Gitlab
::
ImportExport
::
RepoRestorer
.
new
(
path_to_bundle:
repo_path
,
shared:
@shared
,
project:
project_tree
.
project
).
restore
end
def
restore_wiki_repo
Gitlab
::
ImportExport
::
RepoRestorer
.
new
(
path_to_bundle:
wiki_repo_path
,
shared:
@shared
,
project:
ProjectWiki
.
new
(
project_tree
.
project
)).
restore
end
def
storage_path
@storage_path
||=
Gitlab
::
ImportExport
.
export_path
(
relative_path:
path_with_namespace
)
end
def
path_with_namespace
File
.
join
(
@namespace
.
path
,
@project_path
)
end
def
repo_path
File
.
join
(
storage
_path
,
'project.bundle'
)
File
.
join
(
@shared
.
export
_path
,
'project.bundle'
)
end
def
wiki_repo_path
File
.
join
(
storage
_path
,
'project.wiki.bundle'
)
File
.
join
(
@shared
.
export
_path
,
'project.wiki.bundle'
)
end
end
end
...
...
lib/gitlab/import_export/importer.rb
View file @
a61456e4
...
...
@@ -7,20 +7,23 @@ module Gitlab
new
(
*
args
).
import
end
def
initialize
(
archive_file:
,
s
torage_path
:)
def
initialize
(
archive_file:
,
s
hared
:)
@archive_file
=
archive_file
@s
torage_path
=
storage_path
@s
hared
=
shared
end
def
import
FileUtils
.
mkdir_p
(
@storage_path
)
FileUtils
.
mkdir_p
(
@s
hared
.
s
torage_path
)
decompress_archive
rescue
=>
e
@shared
.
error
(
e
.
message
)
false
end
private
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
...
...
lib/gitlab/import_export/project_tree_restorer.rb
View file @
a61456e4
...
...
@@ -2,11 +2,12 @@ module Gitlab
module
ImportExport
class
ProjectTreeRestorer
def
initialize
(
path
:,
user
:,
project_path
:,
namespace_id
:)
@path
=
File
.
join
(
path
,
'project.json'
)
def
initialize
(
user
:,
shared
:,
namespace_id
:)
@path
=
File
.
join
(
shared
.
export_
path
,
'project.json'
)
@user
=
user
@project_path
=
project_path
@project_path
=
shared
.
opts
[
:project_path
]
@namespace_id
=
namespace_id
@shared
=
shared
end
def
restore
...
...
@@ -15,7 +16,7 @@ module Gitlab
@project_members
=
@tree_hash
.
delete
(
'project_members'
)
create_relations
rescue
=>
e
# TODO: handle errors better, move them to a shared thing
@shared
.
error
(
e
.
message
)
false
end
...
...
@@ -44,7 +45,9 @@ module Gitlab
end
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
def
create_project
...
...
lib/gitlab/import_export/repo_restorer.rb
View file @
a61456e4
...
...
@@ -3,9 +3,10 @@ module Gitlab
class
RepoRestorer
include
Gitlab
::
ImportExport
::
CommandLineUtil
def
initialize
(
project
:,
path_to_bundle
:)
def
initialize
(
project
:,
shared
:,
path_to_bundle
:)
@project
=
project
@path_to_bundle
=
path_to_bundle
@shared
=
shared
end
def
restore
...
...
@@ -15,7 +16,8 @@ module Gitlab
FileUtils
.
mkdir_p
(
path_to_repo
)
git_unbundle
(
repo_path:
path_to_repo
,
bundle_path:
@path_to_bundle
)
rescue
rescue
=>
e
@shared
.
error
(
e
.
message
)
false
end
...
...
lib/gitlab/import_export/shared.rb
View file @
a61456e4
...
...
@@ -2,7 +2,7 @@ module Gitlab
module
ImportExport
class
Shared
attr_reader
:errors
attr_reader
:errors
,
:opts
def
initialize
(
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
let
(
:user
)
{
create
(
: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
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