Commit d33db654 authored by Michael Leopard's avatar Michael Leopard Committed by Douglas Barbosa Alexandre

Exposing name property in imports API

Updating import API documentation. Updating import API tests.
parent 04dea3d9
---
title: Expose name property in imports API
merge_request: 16848
author:
type: added
...@@ -111,6 +111,7 @@ POST /projects/import ...@@ -111,6 +111,7 @@ POST /projects/import
| Attribute | Type | Required | Description | | Attribute | Type | Required | Description |
| --------- | -------------- | -------- | ---------------------------------------- | | --------- | -------------- | -------- | ---------------------------------------- |
| `namespace` | integer/string | no | The ID or path of the namespace that the project will be imported to. Defaults to the current user's namespace | | `namespace` | integer/string | no | The ID or path of the namespace that the project will be imported to. Defaults to the current user's namespace |
| `name` | string | no | The name of the project to be imported. Defaults to the path of the project if not provided |
| `file` | string | yes | The file to be uploaded | | `file` | string | yes | The file to be uploaded |
| `path` | string | yes | Name and path for new project | | `path` | string | yes | Name and path for new project |
| `overwrite` | boolean | no | If there is a project with the same path the import will overwrite it. Default to false | | `overwrite` | boolean | no | If there is a project with the same path the import will overwrite it. Default to false |
...@@ -131,14 +132,12 @@ cURL doesn't support posting a file from a remote server. Importing a project fr ...@@ -131,14 +132,12 @@ cURL doesn't support posting a file from a remote server. Importing a project fr
```python ```python
import requests import requests
import urllib from io import BytesIO
import json
import sys
s3_file = urllib.urlopen(presigned_url) s3_file = requests.get(presigned_url)
url = 'https://gitlab.example.com/api/v4/projects/import' url = 'https://gitlab.example.com/api/v4/projects/import'
files = {'file': s3_file} files = {'file': BytesIO(s3_file.content)}
data = { data = {
"path": "example-project", "path": "example-project",
"namespace": "example-group" "namespace": "example-group"
......
...@@ -29,6 +29,7 @@ module API ...@@ -29,6 +29,7 @@ module API
requires :path, type: String, desc: 'The new project path and name' requires :path, type: String, desc: 'The new project path and name'
# TODO: remove rubocop disable - https://gitlab.com/gitlab-org/gitlab/issues/14960 # TODO: remove rubocop disable - https://gitlab.com/gitlab-org/gitlab/issues/14960
requires :file, type: File, desc: 'The project export file to be imported' # rubocop:disable Scalability/FileUploads requires :file, type: File, desc: 'The project export file to be imported' # rubocop:disable Scalability/FileUploads
optional :name, type: String, desc: 'The name of the project to be imported. Defaults to the path of the project if not provided.'
optional :namespace, type: String, desc: "The ID or name of the namespace that the project will be imported into. Defaults to the current user's namespace." optional :namespace, type: String, desc: "The ID or name of the namespace that the project will be imported into. Defaults to the current user's namespace."
optional :overwrite, type: Boolean, default: false, desc: 'If there is a project in the same namespace and with the same name overwrite it' optional :overwrite, type: Boolean, default: false, desc: 'If there is a project in the same namespace and with the same name overwrite it'
optional :override_params, optional :override_params,
...@@ -55,6 +56,7 @@ module API ...@@ -55,6 +56,7 @@ module API
project_params = { project_params = {
path: import_params[:path], path: import_params[:path],
namespace_id: namespace.id, namespace_id: namespace.id,
name: import_params[:name],
file: import_params[:file]['tempfile'], file: import_params[:file]['tempfile'],
overwrite: import_params[:overwrite] overwrite: import_params[:overwrite]
} }
......
...@@ -33,6 +33,53 @@ describe API::ProjectImport do ...@@ -33,6 +33,53 @@ describe API::ProjectImport do
expect(response).to have_gitlab_http_status(201) expect(response).to have_gitlab_http_status(201)
end end
context 'when a name is explicitly set' do
let(:expected_name) { 'test project import' }
it 'schedules an import using a namespace and a different name' do
stub_import(namespace)
post api('/projects/import', user), params: { path: 'test-import', file: fixture_file_upload(file), namespace: namespace.id, name: expected_name }
expect(response).to have_gitlab_http_status(201)
end
it 'schedules an import using the namespace path and a different name' do
stub_import(namespace)
post api('/projects/import', user), params: { path: 'test-import', file: fixture_file_upload(file), namespace: namespace.full_path, name: expected_name }
expect(response).to have_gitlab_http_status(201)
end
it 'sets name correctly' do
stub_import(namespace)
post api('/projects/import', user), params: { path: 'test-import', file: fixture_file_upload(file), namespace: namespace.full_path, name: expected_name }
project = Project.find(json_response['id'])
expect(project.name).to eq(expected_name)
end
it 'sets name correctly with an overwrite' do
stub_import(namespace)
post api('/projects/import', user), params: { path: 'test-import', file: fixture_file_upload(file), namespace: namespace.full_path, name: 'new project name', overwrite: true }
project = Project.find(json_response['id'])
expect(project.name).to eq('new project name')
end
it 'schedules an import using the path and name explicitly set to nil' do
stub_import(namespace)
post api('/projects/import', user), params: { path: 'test-import', file: fixture_file_upload(file), namespace: namespace.full_path, name: nil }
project = Project.find(json_response['id'])
expect(project.name).to eq('test-import')
end
end
it 'schedules an import at the user namespace level' do it 'schedules an import at the user namespace level' do
stub_import(user.namespace) stub_import(user.namespace)
......
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