diff options
author | Francisco Javier López <fjlopez@gitlab.com> | 2018-04-06 18:23:49 +0300 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2018-04-06 18:23:49 +0300 |
commit | f20912df033d07c46b0989012244d96d0a12b66d (patch) | |
tree | 6207b8face17f9b7166ba1a5e047032e3927e53e /app/services/projects/gitlab_projects_import_service.rb | |
parent | 44f4a674e2a87d104f700265d835aba000c589f0 (diff) |
Extend API for importing a project export with overwrite support
Diffstat (limited to 'app/services/projects/gitlab_projects_import_service.rb')
-rw-r--r-- | app/services/projects/gitlab_projects_import_service.rb | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/app/services/projects/gitlab_projects_import_service.rb b/app/services/projects/gitlab_projects_import_service.rb index fb4afb85588..a16268f4fd2 100644 --- a/app/services/projects/gitlab_projects_import_service.rb +++ b/app/services/projects/gitlab_projects_import_service.rb @@ -15,9 +15,18 @@ module Projects file = params.delete(:file) FileUtils.copy_entry(file.path, import_upload_path) + @overwrite = params.delete(:overwrite) + data = {} + data[:override_params] = @override_params if @override_params + + if overwrite_project? + data[:original_path] = params[:path] + params[:path] += "-#{tmp_filename}" + end + params[:import_type] = 'gitlab_project' params[:import_source] = import_upload_path - params[:import_data] = { data: { override_params: @override_params } } if @override_params + params[:import_data] = { data: data } if data.present? ::Projects::CreateService.new(current_user, params).execute end @@ -31,5 +40,17 @@ module Projects def tmp_filename SecureRandom.hex end + + def overwrite_project? + @overwrite && project_with_same_full_path? + end + + def project_with_same_full_path? + Project.find_by_full_path("#{current_namespace.full_path}/#{params[:path]}").present? + end + + def current_namespace + @current_namespace ||= Namespace.find_by(id: params[:namespace_id]) + end end end |