summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorSean McGivern <sean@mcgivern.me.uk>2018-03-06 15:24:14 +0000
committerSean McGivern <sean@mcgivern.me.uk>2018-03-06 15:24:14 +0000
commit39b393fa72026eeddd141c03696310162304ea98 (patch)
tree0141fded5989d81794e51992d237bd12ff2ea140 /lib
parent5e8138aa54492dd3ace42d889ba01f82e8e19c83 (diff)
parent3e71955befba95f823ba92290dedc13a9bf332ff (diff)
downloadgitlab-ce-39b393fa72026eeddd141c03696310162304ea98.tar.gz
Merge branch '29130-api-project-export' into 'master'
Resolve "API endpoint for exporting project" Closes #29130 See merge request gitlab-org/gitlab-ce!15860
Diffstat (limited to 'lib')
-rw-r--r--lib/api/api.rb1
-rw-r--r--lib/api/entities.rb15
-rw-r--r--lib/api/project_export.rb41
-rw-r--r--lib/gitlab/import_export/importer.rb2
-rw-r--r--lib/gitlab/import_export/shared.rb14
5 files changed, 67 insertions, 6 deletions
diff --git a/lib/api/api.rb b/lib/api/api.rb
index b1b247b70b9..42d850d6778 100644
--- a/lib/api/api.rb
+++ b/lib/api/api.rb
@@ -139,6 +139,7 @@ module API
mount ::API::PagesDomains
mount ::API::Pipelines
mount ::API::PipelineSchedules
+ mount ::API::ProjectExport
mount ::API::ProjectImport
mount ::API::ProjectHooks
mount ::API::Projects
diff --git a/lib/api/entities.rb b/lib/api/entities.rb
index e5bcbface6b..f39906270d8 100644
--- a/lib/api/entities.rb
+++ b/lib/api/entities.rb
@@ -91,6 +91,21 @@ module API
expose :created_at
end
+ class ProjectExportStatus < ProjectIdentity
+ include ::API::Helpers::RelatedResourcesHelpers
+
+ expose :export_status
+ expose :_links, if: lambda { |project, _options| project.export_status == :finished } do
+ expose :api_url do |project|
+ expose_url(api_v4_projects_export_download_path(id: project.id))
+ end
+
+ expose :web_url do |project|
+ Gitlab::Routing.url_helpers.download_export_project_url(project)
+ end
+ end
+ end
+
class ProjectImportStatus < ProjectIdentity
expose :import_status
diff --git a/lib/api/project_export.rb b/lib/api/project_export.rb
new file mode 100644
index 00000000000..6ec2626df1a
--- /dev/null
+++ b/lib/api/project_export.rb
@@ -0,0 +1,41 @@
+module API
+ class ProjectExport < Grape::API
+ before do
+ not_found! unless Gitlab::CurrentSettings.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
+ detail 'This feature was introduced in GitLab 10.6.'
+ success Entities::ProjectExportStatus
+ end
+ get ':id/export' do
+ present user_project, with: Entities::ProjectExportStatus
+ end
+
+ desc 'Download export' do
+ detail 'This feature was introduced in GitLab 10.6.'
+ end
+ 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' do
+ detail 'This feature was introduced in GitLab 10.6.'
+ end
+ post ':id/export' do
+ user_project.add_export_job(current_user: current_user)
+
+ accepted!
+ end
+ end
+ end
+end
diff --git a/lib/gitlab/import_export/importer.rb b/lib/gitlab/import_export/importer.rb
index a00795f553e..c38df9102eb 100644
--- a/lib/gitlab/import_export/importer.rb
+++ b/lib/gitlab/import_export/importer.rb
@@ -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 = project.import_export_shared
end
def execute
diff --git a/lib/gitlab/import_export/shared.rb b/lib/gitlab/import_export/shared.rb
index b34cafc6876..3d3d998a6a3 100644
--- a/lib/gitlab/import_export/shared.rb
+++ b/lib/gitlab/import_export/shared.rb
@@ -1,13 +1,17 @@
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,11 @@ 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], '..')
+ @project.disk_path
end
def error_out(message, caller)