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
Boxiang Sun
gitlab-ce
Commits
9d306eb1
Commit
9d306eb1
authored
May 03, 2016
by
James Lopez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
picking stuff from ui related to import
parent
548c91e3
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
65 additions
and
22 deletions
+65
-22
app/models/project.rb
app/models/project.rb
+10
-0
app/workers/project_impor_worker.rb
app/workers/project_impor_worker.rb
+25
-0
lib/gitlab/import_export/import_service.rb
lib/gitlab/import_export/import_service.rb
+15
-10
lib/gitlab/import_export/importer.rb
lib/gitlab/import_export/importer.rb
+2
-1
lib/gitlab/import_export/project_tree_restorer.rb
lib/gitlab/import_export/project_tree_restorer.rb
+8
-7
lib/gitlab/import_export/repo_restorer.rb
lib/gitlab/import_export/repo_restorer.rb
+5
-4
No files found.
app/models/project.rb
View file @
9d306eb1
...
...
@@ -359,6 +359,16 @@ class Project < ActiveRecord::Base
def
visible_to_user
(
user
)
where
(
id:
user
.
authorized_projects
.
select
(
:id
).
reorder
(
nil
))
end
def
create_from_import_job
(
current_user_id
:,
tmp_file
:,
namespace_id
:,
project_path
:)
job_id
=
ProjectImportWorker
.
perform_async
(
current_user_id
,
tmp_file
,
namespace_id
,
project_path
)
if
job_id
Rails
.
logger
.
info
"Import job started for export
#{
tmp_file
}
with job ID
#{
job_id
}
"
else
Rails
.
logger
.
error
"Import job failed to start for
#{
tmp_file
}
"
end
end
end
def
team
...
...
app/workers/project_impor_worker.rb
0 → 100644
View file @
9d306eb1
class
ProjectImportWorker
include
Sidekiq
::
Worker
include
Gitlab
::
ShellAdapter
sidekiq_options
queue: :gitlab_shell
,
retry:
false
def
perform
(
current_user_id
,
tmp_file
,
namespace_id
,
path
)
current_user
=
User
.
find
(
current_user_id
)
project
=
Gitlab
::
ImportExport
::
ImportService
.
execute
(
archive_file:
tmp_file
,
owner:
current_user
,
namespace_id:
namespace_id
,
project_path:
path
)
# TODO: Move this to import service
# if result[:status] == :error
# project.update(import_error: result[:message])
# project.import_fail
# return
# end
project
.
repository
.
after_import
project
.
import_finish
end
end
\ No newline at end of file
lib/gitlab/import_export/import_service.rb
View file @
9d306eb1
...
...
@@ -3,18 +3,19 @@ module Gitlab
class
ImportService
def
self
.
execute
(
*
args
)
new
(
args
).
execute
new
(
*
args
).
execute
end
def
initialize
(
options
=
{})
@archive_file
=
options
[
:archive_file
]
@current_user
=
options
[
:owner
]
def
initialize
(
archive_file
:,
owner
:,
namespace_id
:,
project_path
:)
@archive_file
=
archive_file
@current_user
=
owner
@namespace_path
=
Namespace
.
find
(
namespace_id
).
path
@project_path
=
project_path
end
def
execute
Gitlab
::
ImportExport
::
Importer
.
import
(
archive_file:
@archive_file
,
storage_path:
storage_path
)
restore_project_tree
restore_repo
(
project_tree
.
project
)
project_tree
.
project
if
[
restore_project_tree
,
restore_repo
].
all?
end
private
...
...
@@ -24,15 +25,19 @@ module Gitlab
end
def
project_tree
@project_tree
||=
Gitlab
::
ImportExport
::
ProjectTreeRestorer
.
new
(
path:
storage_path
,
user:
@current_user
)
@project_tree
||=
Gitlab
::
ImportExport
::
ProjectTreeRestorer
.
new
(
path:
storage_path
,
user:
@current_user
,
project_path:
@project_path
)
end
def
restore_repo
(
project
)
Gitlab
::
ImportExport
::
RepoRestorer
.
new
(
path:
storage_path
,
project:
project
).
restore
def
restore_repo
Gitlab
::
ImportExport
::
RepoRestorer
.
new
(
path:
storage_path
,
project:
project
_tree
.
project
).
restore
end
def
storage_path
@storage_path
||=
Gitlab
::
ImportExport
.
export_path
(
relative_path:
project
.
path_with_namespace
)
@storage_path
||=
Gitlab
::
ImportExport
.
export_path
(
relative_path:
path_with_namespace
)
end
def
path_with_namespace
File
.
join
(
@namespace_path
,
@project_path
)
end
end
end
...
...
lib/gitlab/import_export/importer.rb
View file @
9d306eb1
...
...
@@ -13,13 +13,14 @@ module Gitlab
end
def
import
FileUtils
.
mkdir_p
(
@storage_path
)
decompress_archive
end
private
def
decompress_archive
untar_
cz
f
(
archive:
@archive_file
,
dir:
@storage_path
)
untar_
zx
f
(
archive:
@archive_file
,
dir:
@storage_path
)
end
end
end
...
...
lib/gitlab/import_export/project_tree_restorer.rb
View file @
9d306eb1
module
Gitlab
module
ImportExport
class
ProjectTreeRestorer
attr_reader
:project
def
initialize
(
path
:,
user
:)
def
initialize
(
path
:,
user
:
,
project_path
:
)
@path
=
File
.
join
(
path
,
'project.json'
)
@user
=
user
@project_path
=
project_path
end
def
restore
...
...
@@ -15,6 +15,10 @@ module Gitlab
create_relations
end
def
project
@project
||=
create_project
end
private
def
members_map
...
...
@@ -40,14 +44,12 @@ module Gitlab
Gitlab
::
ImportExport
::
ImportExportReader
.
tree
.
reject
{
|
model
|
model
.
is_a?
(
Hash
)
&&
model
[
:project_members
]
}
end
def
project
@project
||=
create_project
end
def
create_project
project_params
=
@tree_hash
.
reject
{
|
_key
,
value
|
value
.
is_a?
(
Array
)
}
project
=
Gitlab
::
ImportExport
::
ProjectFactory
.
create
(
project_params:
project_params
,
user:
@user
)
project
.
path
=
@project_path
project
.
name
=
@project_path
project
.
save
project
end
...
...
@@ -63,7 +65,6 @@ module Gitlab
end
def
process_sub_relation
(
relation_hash
,
relation_item
,
sub_relation
)
sub_relation_object
=
nil
if
relation_hash
.
is_a?
(
Array
)
sub_relation_object
=
create_relation
(
sub_relation
,
relation_hash
)
else
...
...
lib/gitlab/import_export/repo_restorer.rb
View file @
9d306eb1
...
...
@@ -3,18 +3,19 @@ module Gitlab
class
RepoRestorer
include
Gitlab
::
ImportExport
::
CommandLineUtil
def
initialize
(
project:
,
path
:
,
bundler_file:
)
def
initialize
(
project:
,
path:
)
@project
=
project
@path
=
File
.
join
(
path
,
bundler_file
)
# TODO remove magic keyword and move it to a shared config
@path
=
File
.
join
(
path
,
'project.bundle'
)
end
def
restore
return
false
unless
File
.
exists?
(
@path
)
# Move repos dir to 'repositories.old' dir
# Move repos dir to 'repositories.old' dir
FileUtils
.
mkdir_p
(
repos_path
)
FileUtils
.
mkdir_p
(
path_to_repo
)
untar_
c
f
(
archive:
@path
,
dir:
path_to_repo
)
untar_
x
f
(
archive:
@path
,
dir:
path_to_repo
)
end
private
...
...
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