summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Lopez <james@jameslopez.es>2018-02-13 09:24:10 +0100
committerJames Lopez <james@jameslopez.es>2018-02-13 15:25:48 +0100
commit583ed0eb94ff938b4986491e27af5f3c97ea6baf (patch)
tree0102e58fa8f4789af8e0d2ce3745ba9583492896
parent7ec1a022b79c68dd3232c0abf07d119f0dad808f (diff)
downloadgitlab-ce-583ed0eb94ff938b4986491e27af5f3c97ea6baf.tar.gz
add import status endpoint
-rw-r--r--lib/api/project_import.rb26
-rw-r--r--spec/requests/api/project_import_spec.rb4
2 files changed, 20 insertions, 10 deletions
diff --git a/lib/api/project_import.rb b/lib/api/project_import.rb
index 5a4e4189a58..d554d6d12bd 100644
--- a/lib/api/project_import.rb
+++ b/lib/api/project_import.rb
@@ -16,12 +16,13 @@ module API
not_found! unless Gitlab::CurrentSettings.import_sources.include?('gitlab_project')
end
- params do
- requires :path, type: String, desc: 'The new project path and name'
- optional :namespace, type: String, desc: 'The ID or name of the namespace that the project will be imported into. Defaults to the user namespace.'
- requires :file, type: File, desc: 'The project export file to be imported'
- end
- resource :projects do
+ resource :projects, requirements: { id: %r{[^/]+} } do
+
+ params do
+ requires :path, type: String, desc: 'The new project path and name'
+ optional :namespace, type: String, desc: 'The ID or name of the namespace that the project will be imported into. Defaults to the user namespace.'
+ requires :file, type: File, desc: 'The project export file to be imported'
+ end
desc 'Get export status' do
success Entities::ProjectImportStatus
end
@@ -40,13 +41,22 @@ module API
project_params = import_params.merge(namespace_id: namespace.id,
file: import_params[:file]['tempfile'])
-
project = ::Projects::GitlabProjectsImportService.new(current_user, project_params).execute
- render_api_error!(project.full_messages.first, 400) unless project.saved?
+ render_api_error!(project&.full_messages&.first, 400) unless project&.saved?
present project, with: Entities::ProjectImportStatus
end
+
+ params do
+ requires :id, type: String, desc: 'The ID of a project'
+ end
+ desc 'Get export status' do
+ success Entities::ProjectImportStatus
+ end
+ get ':id/import' do
+ present user_project, with: Entities::ProjectImportStatus
+ end
end
end
end
diff --git a/spec/requests/api/project_import_spec.rb b/spec/requests/api/project_import_spec.rb
index 3c9a05f93ea..cbea0229b09 100644
--- a/spec/requests/api/project_import_spec.rb
+++ b/spec/requests/api/project_import_spec.rb
@@ -22,14 +22,13 @@ describe API::ProjectImport do
post api('/projects/import', user), path: 'test-import', file: fixture_file_upload(file), namespace: namespace.full_path
expect(response).to have_gitlab_http_status(201)
-
- expect(Project.find_by_name('test-import').first.status).to eq('started')
end
end
describe 'GET /projects/:id/import' do
it 'returns the import status' do
project = create(:project, import_status: 'started')
+ project.add_master(user)
get api("/projects/#{project.id}/import", user)
@@ -39,6 +38,7 @@ describe API::ProjectImport do
it 'returns the import status and the error if failed' do
project = create(:project, import_status: 'failed', import_error: 'error')
+ project.add_master(user)
get api("/projects/#{project.id}/import", user)