Commit 583ed0eb authored by James Lopez's avatar James Lopez

add import status endpoint

parent 7ec1a022
......@@ -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
......@@ -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)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment