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
0852f539
Commit
0852f539
authored
Apr 14, 2016
by
James Lopez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactored stuff, added a save and compress all class and moved mostly everything to lib
parent
91ffd802
Changes
14
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
83 additions
and
33 deletions
+83
-33
app/services/projects/import_export/export_service.rb
app/services/projects/import_export/export_service.rb
+8
-3
lib/gitlab/import_export.rb
lib/gitlab/import_export.rb
+3
-3
lib/gitlab/import_export/command_line_util.rb
lib/gitlab/import_export/command_line_util.rb
+12
-4
lib/gitlab/import_export/import_export.yml
lib/gitlab/import_export/import_export.yml
+0
-0
lib/gitlab/import_export/import_export_reader.rb
lib/gitlab/import_export/import_export_reader.rb
+2
-2
lib/gitlab/import_export/project_tree_saver.rb
lib/gitlab/import_export/project_tree_saver.rb
+2
-3
lib/gitlab/import_export/repo_bundler.rb
lib/gitlab/import_export/repo_bundler.rb
+2
-2
lib/gitlab/import_export/saver.rb
lib/gitlab/import_export/saver.rb
+38
-0
lib/gitlab/import_export/shared.rb
lib/gitlab/import_export/shared.rb
+2
-2
lib/gitlab/import_export/wiki_repo_bundler.rb
lib/gitlab/import_export/wiki_repo_bundler.rb
+1
-1
spec/lib/gitlab/import_export/import_export_reader_spec.rb
spec/lib/gitlab/import_export/import_export_reader_spec.rb
+1
-1
spec/lib/gitlab/import_export/project_tree_saver_spec.rb
spec/lib/gitlab/import_export/project_tree_saver_spec.rb
+4
-4
spec/lib/gitlab/import_export/repo_bundler_spec.rb
spec/lib/gitlab/import_export/repo_bundler_spec.rb
+4
-4
spec/lib/gitlab/import_export/wiki_repo_bundler_spec.rb
spec/lib/gitlab/import_export/wiki_repo_bundler_spec.rb
+4
-4
No files found.
app/services/projects/import_export/export_service.rb
View file @
0852f539
...
@@ -2,19 +2,24 @@ module Projects
...
@@ -2,19 +2,24 @@ module Projects
module
ImportExport
module
ImportExport
class
ExportService
<
BaseService
class
ExportService
<
BaseService
def
execute
(
options
=
{})
def
execute
(
options
=
{})
@shared
=
Projects
::
ImportExport
::
Shared
.
new
(
relative_path:
project
.
path_with_namespace
)
@shared
=
Gitlab
::
ImportExport
::
Shared
.
new
(
relative_path:
project
.
path_with_namespace
)
save_project_tree
save_project_tree
bundle_repo
bundle_repo
save_all
end
end
private
private
def
save_project_tree
def
save_project_tree
Projects
::
ImportExport
::
ProjectTreeSaver
.
new
(
project:
project
,
shared:
@shared
).
save
Gitlab
::
ImportExport
::
ProjectTreeSaver
.
new
(
project:
project
,
shared:
@shared
).
save
end
end
def
bundle_repo
def
bundle_repo
Projects
::
ImportExport
::
RepoBundler
.
new
(
project:
project
,
shared:
@shared
).
bundle
Gitlab
::
ImportExport
::
RepoBundler
.
new
(
project:
project
,
shared:
@shared
).
bundle
end
def
save_all
Gitlab
::
ImportExport
::
Saver
.
save
(
storage_path:
@shared
.
export_path
)
end
end
end
end
end
end
...
...
app/services/projects
/import_export.rb
→
lib/gitlab
/import_export.rb
View file @
0852f539
module
Projects
module
Gitlab
module
ImportExport
module
ImportExport
extend
self
extend
self
def
export_path
(
relative_path
:)
def
export_path
(
relative_path
:)
File
.
join
(
storage_path
,
"
#{
Time
.
now
.
strftime
(
'%Y-%m-%d_%H-%M-%3N'
)
}
_gitlab_export/
#{
relative_path
}
"
)
File
.
join
(
storage_path
,
relative_path
,
"
#{
Time
.
now
.
strftime
(
'%Y-%m-%d_%H-%M-%3N'
)
}
_gitlab_export
"
)
end
end
def
project_atts
def
project_atts
...
@@ -11,7 +11,7 @@ module Projects
...
@@ -11,7 +11,7 @@ module Projects
end
end
def
project_tree
def
project_tree
Projects
::
ImportExport
::
ImportExportReader
.
project_tree
Gitlab
::
ImportExport
::
ImportExportReader
.
project_tree
end
end
private
private
...
...
app/services/projects
/import_export/command_line_util.rb
→
lib/gitlab
/import_export/command_line_util.rb
View file @
0852f539
module
Projects
module
Gitlab
module
ImportExport
module
ImportExport
module
CommandLineUtil
module
CommandLineUtil
def
tar_cf
(
archive
:,
dir
:)
def
tar_cf
(
archive
:,
dir
:)
cmd
=
%W(tar -cf
#{
archive
}
-C
#{
dir
}
.)
tar_with_options
(
archive:
archive
,
dir:
dir
,
options:
'cf'
)
_output
,
status
=
Gitlab
::
Popen
.
popen
(
cmd
)
end
status
.
zero?
def
tar_czf
(
archive
:,
dir
:)
tar_with_options
(
archive:
archive
,
dir:
dir
,
options:
'czf'
)
end
end
def
git_bundle
(
git_bin_path:
Gitlab
.
config
.
git
.
bin_path
,
repo_path
:,
bundle_path
:)
def
git_bundle
(
git_bin_path:
Gitlab
.
config
.
git
.
bin_path
,
repo_path
:,
bundle_path
:)
...
@@ -12,6 +14,12 @@ module Projects
...
@@ -12,6 +14,12 @@ module Projects
_output
,
status
=
Gitlab
::
Popen
.
popen
(
cmd
)
_output
,
status
=
Gitlab
::
Popen
.
popen
(
cmd
)
status
.
zero?
status
.
zero?
end
end
def
tar_with_options
(
archive
:,
dir
:,
options
:)
cmd
=
%W(tar -
#{
options
}
#{
archive
}
-C
#{
dir
}
.)
_output
,
status
=
Gitlab
::
Popen
.
popen
(
cmd
)
status
.
zero?
end
end
end
end
end
end
end
app/services/projects
/import_export/import_export.yml
→
lib/gitlab
/import_export/import_export.yml
View file @
0852f539
File moved
app/services/projects
/import_export/import_export_reader.rb
→
lib/gitlab
/import_export/import_export_reader.rb
View file @
0852f539
module
Projects
module
Gitlab
module
ImportExport
module
ImportExport
module
ImportExportReader
module
ImportExportReader
extend
self
extend
self
...
@@ -14,7 +14,7 @@ module Projects
...
@@ -14,7 +14,7 @@ module Projects
private
private
def
config
def
config
@config
||=
YAML
.
load_file
(
'
app/services/projects
/import_export/import_export.yml'
)
@config
||=
YAML
.
load_file
(
'
lib/gitlab
/import_export/import_export.yml'
)
end
end
def
atts_only
def
atts_only
...
...
app/services/projects
/import_export/project_tree_saver.rb
→
lib/gitlab
/import_export/project_tree_saver.rb
View file @
0852f539
module
Projects
module
Gitlab
module
ImportExport
module
ImportExport
class
ProjectTreeSaver
class
ProjectTreeSaver
attr_reader
:full_path
attr_reader
:full_path
...
@@ -25,12 +25,11 @@ module Projects
...
@@ -25,12 +25,11 @@ module Projects
end
end
def
project_filename
def
project_filename
# TODO sanitize name
"
#{
@project
.
name
}
.json"
"
#{
@project
.
name
}
.json"
end
end
def
project_json_tree
def
project_json_tree
@project
.
to_json
(
Projects
::
ImportExport
.
project_tree
)
@project
.
to_json
(
Gitlab
::
ImportExport
.
project_tree
)
end
end
end
end
end
end
...
...
app/services/projects
/import_export/repo_bundler.rb
→
lib/gitlab
/import_export/repo_bundler.rb
View file @
0852f539
module
Projects
module
Gitlab
module
ImportExport
module
ImportExport
class
RepoBundler
class
RepoBundler
include
Projects
::
ImportExport
::
CommandLineUtil
include
Gitlab
::
ImportExport
::
CommandLineUtil
attr_reader
:full_path
attr_reader
:full_path
...
...
lib/gitlab/import_export/saver.rb
0 → 100644
View file @
0852f539
module
Gitlab
module
ImportExport
class
Saver
include
Gitlab
::
ImportExport
::
CommandLineUtil
def
self
.
save
(
*
args
)
new
(
*
args
).
save
end
def
initialize
(
storage_path
:)
@storage_path
=
storage_path
end
def
save
if
compress_and_save
remove_storage_path
archive_file
else
false
end
end
private
def
compress_and_save
tar_czf
(
archive:
archive_file
,
dir:
@storage_path
)
end
def
remove_storage_path
FileUtils
.
rm_rf
(
@storage_path
)
end
def
archive_file
@archive_file
||=
File
.
join
(
@storage_path
,
'..'
,
'project.tar.gz'
)
end
end
end
end
app/services/projects
/import_export/shared.rb
→
lib/gitlab
/import_export/shared.rb
View file @
0852f539
module
Projects
module
Gitlab
module
ImportExport
module
ImportExport
class
Shared
class
Shared
def
initialize
(
opts
)
def
initialize
(
opts
)
...
@@ -6,7 +6,7 @@ module Projects
...
@@ -6,7 +6,7 @@ module Projects
end
end
def
export_path
def
export_path
@export_path
||=
Projects
::
ImportExport
.
export_path
(
relative_path:
@opts
[
:relative_path
])
@export_path
||=
Gitlab
::
ImportExport
.
export_path
(
relative_path:
@opts
[
:relative_path
])
end
end
end
end
end
end
...
...
app/services/projects
/import_export/wiki_repo_bundler.rb
→
lib/gitlab
/import_export/wiki_repo_bundler.rb
View file @
0852f539
module
Projects
module
Gitlab
module
ImportExport
module
ImportExport
class
WikiRepoBundler
<
RepoBundler
class
WikiRepoBundler
<
RepoBundler
def
bundle
def
bundle
...
...
spec/
services/projects
/import_export/import_export_reader_spec.rb
→
spec/
lib/gitlab
/import_export/import_export_reader_spec.rb
View file @
0852f539
require
'rspec'
require
'rspec'
describe
Projects
::
ImportExport
::
ImportExportReader
do
describe
Gitlab
::
ImportExport
::
ImportExportReader
do
let
(
:test_config
)
{
'spec/support/import_export/import_export.yml'
}
let
(
:test_config
)
{
'spec/support/import_export/import_export.yml'
}
let
(
:project_tree_hash
)
do
let
(
:project_tree_hash
)
do
...
...
spec/
services/projects
/import_export/project_tree_saver_spec.rb
→
spec/
lib/gitlab
/import_export/project_tree_saver_spec.rb
View file @
0852f539
require
'spec_helper'
require
'spec_helper'
describe
Projects
::
ImportExport
::
ProjectTreeSaver
,
services:
true
do
describe
Gitlab
::
ImportExport
::
ProjectTreeSaver
,
services:
true
do
describe
:save
do
describe
:save
do
# TODO refactor this into a setup method
# TODO refactor this into a setup method
...
@@ -26,14 +26,14 @@ describe Projects::ImportExport::ProjectTreeSaver, services: true do
...
@@ -26,14 +26,14 @@ describe Projects::ImportExport::ProjectTreeSaver, services: true do
let!
(
:ci_commit
)
{
create
(
:ci_commit
,
project:
project
,
sha:
merge_request
.
last_commit
.
id
,
ref:
merge_request
.
source_branch
,
statuses:
[
commit_status
])
}
let!
(
:ci_commit
)
{
create
(
:ci_commit
,
project:
project
,
sha:
merge_request
.
last_commit
.
id
,
ref:
merge_request
.
source_branch
,
statuses:
[
commit_status
])
}
let!
(
:milestone
)
{
create
(
:milestone
,
title:
"Milestone v1.2"
,
project:
project
)
}
let!
(
:milestone
)
{
create
(
:milestone
,
title:
"Milestone v1.2"
,
project:
project
)
}
let
(
:export_path
)
{
"
#{
Dir
::
tmpdir
}
/project_tree_saver_spec"
}
let
(
:export_path
)
{
"
#{
Dir
::
tmpdir
}
/project_tree_saver_spec"
}
let
(
:shared
)
{
Projects
::
ImportExport
::
Shared
.
new
(
relative_path:
project
.
path_with_namespace
)
}
let
(
:shared
)
{
Gitlab
::
ImportExport
::
Shared
.
new
(
relative_path:
project
.
path_with_namespace
)
}
let
(
:project_tree_saver
)
{
Projects
::
ImportExport
::
ProjectTreeSaver
.
new
(
project:
project
,
shared:
shared
)
}
let
(
:project_tree_saver
)
{
Gitlab
::
ImportExport
::
ProjectTreeSaver
.
new
(
project:
project
,
shared:
shared
)
}
let!
(
:issue_note
)
{
create
(
:note
,
note:
":+1: issue"
,
noteable:
issue
)
}
let!
(
:issue_note
)
{
create
(
:note
,
note:
":+1: issue"
,
noteable:
issue
)
}
let!
(
:merge_request_note
)
{
create
(
:note
,
note:
":+1: merge_request"
,
noteable:
merge_request
)
}
let!
(
:merge_request_note
)
{
create
(
:note
,
note:
":+1: merge_request"
,
noteable:
merge_request
)
}
before
(
:each
)
do
before
(
:each
)
do
project
.
team
<<
[
user
,
:master
]
project
.
team
<<
[
user
,
:master
]
allow_any_instance_of
(
Projects
::
ImportExport
).
to
receive
(
:storage_path
).
and_return
(
export_path
)
allow_any_instance_of
(
Gitlab
::
ImportExport
).
to
receive
(
:storage_path
).
and_return
(
export_path
)
end
end
after
(
:each
)
do
after
(
:each
)
do
...
...
spec/
services/projects
/import_export/repo_bundler_spec.rb
→
spec/
lib/gitlab
/import_export/repo_bundler_spec.rb
View file @
0852f539
require
'spec_helper'
require
'spec_helper'
describe
Projects
::
ImportExport
::
RepoBundler
,
services:
true
do
describe
Gitlab
::
ImportExport
::
RepoBundler
,
services:
true
do
describe
:bundle
do
describe
:bundle
do
let
(
:user
)
{
create
(
:user
)
}
let
(
:user
)
{
create
(
:user
)
}
let!
(
:project
)
{
create
(
:project
,
:public
,
name:
'searchable_project'
)
}
let!
(
:project
)
{
create
(
:project
,
:public
,
name:
'searchable_project'
)
}
let
(
:export_path
)
{
"
#{
Dir
::
tmpdir
}
/project_tree_saver_spec"
}
let
(
:export_path
)
{
"
#{
Dir
::
tmpdir
}
/project_tree_saver_spec"
}
let
(
:shared
)
{
Projects
::
ImportExport
::
Shared
.
new
(
relative_path:
project
.
path_with_namespace
)
}
let
(
:shared
)
{
Gitlab
::
ImportExport
::
Shared
.
new
(
relative_path:
project
.
path_with_namespace
)
}
let
(
:bundler
)
{
Projects
::
ImportExport
::
RepoBundler
.
new
(
project:
project
,
shared:
shared
)
}
let
(
:bundler
)
{
Gitlab
::
ImportExport
::
RepoBundler
.
new
(
project:
project
,
shared:
shared
)
}
before
(
:each
)
do
before
(
:each
)
do
project
.
team
<<
[
user
,
:master
]
project
.
team
<<
[
user
,
:master
]
allow_any_instance_of
(
Projects
::
ImportExport
).
to
receive
(
:storage_path
).
and_return
(
export_path
)
allow_any_instance_of
(
Gitlab
::
ImportExport
).
to
receive
(
:storage_path
).
and_return
(
export_path
)
end
end
after
(
:each
)
do
after
(
:each
)
do
...
...
spec/
services/projects
/import_export/wiki_repo_bundler_spec.rb
→
spec/
lib/gitlab
/import_export/wiki_repo_bundler_spec.rb
View file @
0852f539
require
'spec_helper'
require
'spec_helper'
describe
Projects
::
ImportExport
::
WikiRepoBundler
,
services:
true
do
describe
Gitlab
::
ImportExport
::
WikiRepoBundler
,
services:
true
do
describe
:bundle
do
describe
:bundle
do
let
(
:user
)
{
create
(
:user
)
}
let
(
:user
)
{
create
(
:user
)
}
let!
(
:project
)
{
create
(
:project
,
:public
,
name:
'searchable_project'
)
}
let!
(
:project
)
{
create
(
:project
,
:public
,
name:
'searchable_project'
)
}
let
(
:export_path
)
{
"
#{
Dir
::
tmpdir
}
/project_tree_saver_spec"
}
let
(
:export_path
)
{
"
#{
Dir
::
tmpdir
}
/project_tree_saver_spec"
}
let
(
:shared
)
{
Projects
::
ImportExport
::
Shared
.
new
(
relative_path:
project
.
path_with_namespace
)
}
let
(
:shared
)
{
Gitlab
::
ImportExport
::
Shared
.
new
(
relative_path:
project
.
path_with_namespace
)
}
let
(
:wiki_bundler
)
{
Projects
::
ImportExport
::
WikiRepoBundler
.
new
(
project:
project
,
shared:
shared
)
}
let
(
:wiki_bundler
)
{
Gitlab
::
ImportExport
::
WikiRepoBundler
.
new
(
project:
project
,
shared:
shared
)
}
let!
(
:project_wiki
)
{
ProjectWiki
.
new
(
project
,
user
)
}
let!
(
:project_wiki
)
{
ProjectWiki
.
new
(
project
,
user
)
}
before
(
:each
)
do
before
(
:each
)
do
project
.
team
<<
[
user
,
:master
]
project
.
team
<<
[
user
,
:master
]
allow_any_instance_of
(
Projects
::
ImportExport
).
to
receive
(
:storage_path
).
and_return
(
export_path
)
allow_any_instance_of
(
Gitlab
::
ImportExport
).
to
receive
(
:storage_path
).
and_return
(
export_path
)
project_wiki
.
wiki
project_wiki
.
wiki
project_wiki
.
create_page
(
"index"
,
"test content"
)
project_wiki
.
create_page
(
"index"
,
"test content"
)
end
end
...
...
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