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
Léo-Paul Géneau
gitlab-ce
Commits
c75187df
Commit
c75187df
authored
Dec 02, 2017
by
Travis Miller
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add project export API implementation
parent
a4308c53
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
54 additions
and
10 deletions
+54
-10
app/models/project.rb
app/models/project.rb
+2
-3
app/services/projects/import_export/export_service.rb
app/services/projects/import_export/export_service.rb
+1
-1
lib/api/api.rb
lib/api/api.rb
+1
-0
lib/api/project_export.rb
lib/api/project_export.rb
+36
-0
lib/gitlab/import_export/importer.rb
lib/gitlab/import_export/importer.rb
+1
-1
lib/gitlab/import_export/shared.rb
lib/gitlab/import_export/shared.rb
+13
-5
No files found.
app/models/project.rb
View file @
c75187df
...
...
@@ -1560,7 +1560,7 @@ class Project < ActiveRecord::Base
def
export_path
return
nil
unless
namespace
.
present?
||
hashed_storage?
(
:repository
)
File
.
join
(
Gitlab
::
ImportExport
.
storage_path
,
disk_path
)
Gitlab
::
ImportExport
::
Shared
.
new
(
self
).
archive_path
end
def
export_project_path
...
...
@@ -1578,8 +1578,7 @@ class Project < ActiveRecord::Base
end
def
export_in_progress?
shared
=
Gitlab
::
ImportExport
::
Shared
.
new
(
relative_path:
File
.
join
(
disk_path
,
'work'
))
File
.
directory?
(
shared
.
export_path
)
Gitlab
::
ImportExport
::
Shared
.
new
(
self
).
active_export_count
>
0
end
def
remove_exports
...
...
app/services/projects/import_export/export_service.rb
View file @
c75187df
...
...
@@ -2,7 +2,7 @@ module Projects
module
ImportExport
class
ExportService
<
BaseService
def
execute
(
_options
=
{})
@shared
=
Gitlab
::
ImportExport
::
Shared
.
new
(
relative_path:
File
.
join
(
project
.
disk_path
,
'work'
)
)
@shared
=
Gitlab
::
ImportExport
::
Shared
.
new
(
project
)
save_all
end
...
...
lib/api/api.rb
View file @
c75187df
...
...
@@ -138,6 +138,7 @@ module API
mount
::
API
::
PagesDomains
mount
::
API
::
Pipelines
mount
::
API
::
PipelineSchedules
mount
::
API
::
ProjectExport
mount
::
API
::
ProjectImport
mount
::
API
::
ProjectHooks
mount
::
API
::
Projects
...
...
lib/api/project_export.rb
0 → 100644
View file @
c75187df
module
API
class
ProjectExport
<
Grape
::
API
before
do
not_found!
unless
Gitlab
::
CurrentSettings
.
current_application_settings
.
project_export_enabled?
authorize_admin_project
end
params
do
requires
:id
,
type:
String
,
desc:
'The ID of a project'
end
resource
:projects
,
requirements:
{
id:
%r{[^/]+}
}
do
desc
'Get export status'
do
success
Entities
::
ProjectExportStatus
end
get
':id/export'
do
present
user_project
,
with:
Entities
::
ProjectExportStatus
end
desc
'Download export'
get
':id/export/download'
do
path
=
user_project
.
export_project_path
render_api_error!
(
'404 Not found or has expired'
,
404
)
unless
path
present_file!
(
path
,
File
.
basename
(
path
),
'application/gzip'
)
end
desc
'Start export'
post
':id/export'
do
user_project
.
add_export_job
(
current_user:
current_user
)
accepted!
end
end
end
end
lib/gitlab/import_export/importer.rb
View file @
c75187df
...
...
@@ -9,7 +9,7 @@ module Gitlab
@archive_file
=
project
.
import_source
@current_user
=
project
.
creator
@project
=
project
@shared
=
Gitlab
::
ImportExport
::
Shared
.
new
(
relative_path:
path_with_namespace
)
@shared
=
Gitlab
::
ImportExport
::
Shared
.
new
(
project
)
end
def
execute
...
...
lib/gitlab/import_export/shared.rb
View file @
c75187df
module
Gitlab
module
ImportExport
class
Shared
attr_reader
:errors
,
:
opts
attr_reader
:errors
,
:
project
def
initialize
(
opts
)
@
opts
=
opts
def
initialize
(
project
)
@
project
=
project
@errors
=
[]
end
def
active_export_count
Dir
[
File
.
join
(
archive_path
,
'*'
)].
count
{
|
name
|
File
.
directory?
(
name
)
}
end
def
export_path
@export_path
||=
Gitlab
::
ImportExport
.
export_path
(
relative_path:
relative_path
)
end
...
...
@@ -31,11 +35,15 @@ module Gitlab
private
def
relative_path
File
.
join
(
opts
[
:relative_path
]
,
SecureRandom
.
hex
)
File
.
join
(
relative_archive_path
,
SecureRandom
.
hex
)
end
def
relative_archive_path
File
.
join
(
opts
[
:relative_path
],
'..'
)
if
@project
.
is_a?
(
Project
)
@project
.
disk_path
else
@project
[
:relative_path
]
end
end
def
error_out
(
message
,
caller
)
...
...
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