summaryrefslogtreecommitdiff
path: root/lib/api/project_import.rb
diff options
context:
space:
mode:
authorJames Lopez <james@jameslopez.es>2018-02-14 14:46:40 +0100
committerJames Lopez <james@jameslopez.es>2018-02-14 14:46:40 +0100
commite613d777b258a4f7070d2b7aaee093901e4b7ed7 (patch)
treeaaaefe41f510e09cdcaf4542973f505619b519ff /lib/api/project_import.rb
parent083194908437f129adcb6e36be40af72ad6d308c (diff)
downloadgitlab-ce-e613d777b258a4f7070d2b7aaee093901e4b7ed7.tar.gz
refactor code based on feedback
Diffstat (limited to 'lib/api/project_import.rb')
-rw-r--r--lib/api/project_import.rb17
1 files changed, 10 insertions, 7 deletions
diff --git a/lib/api/project_import.rb b/lib/api/project_import.rb
index b0511342b63..88fe1d2b5f5 100644
--- a/lib/api/project_import.rb
+++ b/lib/api/project_import.rb
@@ -10,19 +10,24 @@ module API
def file_is_valid?
import_params[:file] && import_params[:file]['tempfile'].respond_to?(:read)
end
+
+ def validate_file!
+ render_api_error!('The file is invalid', 400) unless file_is_valid?
+ end
end
before do
forbidden! unless Gitlab::CurrentSettings.import_sources.include?('gitlab_project')
end
- resource :projects, requirements: { id: %r{[^/]+} } do
+ resource :projects, requirements: API::PROJECT_ENDPOINT_REQUIREMENTS do
params do
requires :path, type: String, desc: 'The new project path and name'
requires :file, type: File, desc: 'The project export file to be imported'
optional :namespace, type: String, desc: 'The ID or name of the namespace that the project will be imported into. Defaults to the user namespace.'
end
desc 'Create a new project import' do
+ detail 'This feature was introduced in GitLab 10.6.'
success Entities::ProjectImportStatus
end
post 'import' do
@@ -30,13 +35,10 @@ module API
Gitlab::QueryLimiting.whitelist('https://gitlab.com/gitlab-org/gitlab-ce/issues/42437')
- namespace = import_params[:namespace]
- namespace = if namespace.blank?
- current_user.namespace
- elsif namespace =~ /^\d+$/
- Namespace.find_by(id: namespace)
+ namespace = if import_params[:namespace]
+ find_namespace!(import_params[:namespace])
else
- Namespace.find_by_path_or_name(namespace)
+ current_user.namespace
end
project_params = import_params.merge(namespace_id: namespace.id,
@@ -52,6 +54,7 @@ module API
requires :id, type: String, desc: 'The ID of a project'
end
desc 'Get a project export status' do
+ detail 'This feature was introduced in GitLab 10.6.'
success Entities::ProjectImportStatus
end
get ':id/import' do