Commit 19d1fc2c authored by Timo Furrer's avatar Timo Furrer
parent 3480111a
...@@ -136,3 +136,23 @@ Example response: ...@@ -136,3 +136,23 @@ Example response:
"url": "https://*****:*****@gitlab.com/gitlab-org/security/gitlab.git" "url": "https://*****:*****@gitlab.com/gitlab-org/security/gitlab.git"
} }
``` ```
## Delete a remote mirror
> [Introduced](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/82778) in GitLab 14.10.
Delete a remote mirror.
```plaintext
DELETE /projects/:id/remote_mirrors/:mirror_id
```
| Attribute | Type | Required | Description |
| :---------- | :----- | :--------- |:------------------|
| `mirror_id` | Integer | yes | Remote mirror ID. |
Example request:
```shell
curl --request DELETE --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/42/remote_mirrors/101486"
```
...@@ -73,6 +73,29 @@ module API ...@@ -73,6 +73,29 @@ module API
render_api_error!(result[:message], result[:http_status]) render_api_error!(result[:message], result[:http_status])
end end
end end
desc 'Delete a single remote mirror' do
detail 'This feature was introduced in GitLab 14.10'
end
params do
requires :mirror_id, type: String, desc: 'The ID of a remote mirror'
end
delete ':id/remote_mirrors/:mirror_id' do
mirror = user_project.remote_mirrors.find(params[:mirror_id])
destroy_conditionally!(mirror) do
mirror_params = declared_params(include_missing: false).merge(_destroy: 1)
mirror_params[:id] = mirror_params.delete(:mirror_id)
update_params = { remote_mirrors_attributes: mirror_params }
# Note: We are using the update service to be consistent with how the controller handles deletion
result = ::Projects::UpdateService.new(user_project, current_user, update_params).execute
if result[:status] != :success
render_api_error!(result[:message], 400)
end
end
end
end end
end end
end end
...@@ -99,4 +99,44 @@ RSpec.describe API::RemoteMirrors do ...@@ -99,4 +99,44 @@ RSpec.describe API::RemoteMirrors do
expect(json_response['keep_divergent_refs']).to eq(true) expect(json_response['keep_divergent_refs']).to eq(true)
end end
end end
describe 'DELETE /projects/:id/remote_mirrors/:mirror_id' do
let(:route) { ->(id) { "/projects/#{project.id}/remote_mirrors/#{id}" } }
let(:mirror) { project.remote_mirrors.first }
it 'requires `admin_remote_mirror` permission' do
expect { delete api(route[mirror.id], developer) }.not_to change { project.remote_mirrors.count }
expect(response).to have_gitlab_http_status(:unauthorized)
end
context 'when the user is a maintainer' do
before do
project.add_maintainer(user)
end
it 'returns 404 for non existing id' do
delete api(route[non_existing_record_id], user)
expect(response).to have_gitlab_http_status(:not_found)
end
it 'returns bad request if the update service fails' do
expect_next_instance_of(Projects::UpdateService) do |service|
expect(service).to receive(:execute).and_return(status: :error, message: 'message')
end
expect { delete api(route[mirror.id], user) }.not_to change { project.remote_mirrors.count }
expect(response).to have_gitlab_http_status(:bad_request)
expect(json_response).to eq({ 'message' => 'message' })
end
it 'deletes a remote mirror' do
expect { delete api(route[mirror.id], user) }.to change { project.remote_mirrors.count }.from(1).to(0)
expect(response).to have_gitlab_http_status(:no_content)
end
end
end
end end
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