Commit 7d5a1826 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Use POST method instead of DELETE when erasing a build

Discussion:
https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/2560#note_3742042
parent 08b8f489
...@@ -122,7 +122,7 @@ ...@@ -122,7 +122,7 @@
- if @build.erasable? - if @build.erasable?
= link_to erase_namespace_project_build_path(@project.namespace, @project, @build), = link_to erase_namespace_project_build_path(@project.namespace, @project, @build),
class: 'btn btn-sm btn-warning', method: :delete, class: 'btn btn-sm btn-warning', method: :post,
data: { confirm: 'Are you sure you want to erase this build?' } do data: { confirm: 'Are you sure you want to erase this build?' } do
= icon('eraser') = icon('eraser')
Erase Erase
......
...@@ -617,7 +617,7 @@ Rails.application.routes.draw do ...@@ -617,7 +617,7 @@ Rails.application.routes.draw do
get :status get :status
post :cancel post :cancel
post :retry post :retry
delete :erase, path: :content post :erase
end end
resource :artifacts, only: [] do resource :artifacts, only: [] do
......
...@@ -344,20 +344,20 @@ Example of response ...@@ -344,20 +344,20 @@ Example of response
Erase a single build of a project (remove build artifacts and a build trace) Erase a single build of a project (remove build artifacts and a build trace)
``` ```
DELETE /projects/:id/builds/:build_id/content POST /projects/:id/builds/:build_id/erase
``` ```
Parameters Parameters
| Attribute | Type | required | Description | | Attribute | Type | required | Description |
|-----------|---------|----------|---------------------| |-------------|---------|----------|---------------------|
| `id` | integer | yes | The ID of a project | | `id` | integer | yes | The ID of a project |
| `build_id` | integer | yes | The ID of a build | | `build_id` | integer | yes | The ID of a build |
Example of request Example of request
``` ```
curl -X DELETE -H "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" "https://gitlab.example.com/api/v3/projects/1/builds/1/content" curl -X POST -H "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" "https://gitlab.example.com/api/v3/projects/1/builds/1/erase"
``` ```
Example of response Example of response
......
...@@ -130,15 +130,15 @@ module API ...@@ -130,15 +130,15 @@ module API
# id (required) - the id of a project # id (required) - the id of a project
# build_id (required) - the id of a build # build_id (required) - the id of a build
# example Request: # example Request:
# delete /projects/:id/build/:build_id/content # post /projects/:id/build/:build_id/erase
delete ':id/builds/:build_id/content' do post ':id/builds/:build_id/erase' do
authorize_update_builds! authorize_update_builds!
build = get_build(params[:build_id]) build = get_build(params[:build_id])
return not_found!(build) unless build return not_found!(build) unless build
return forbidden!('Build is not erasable!') unless build.erasable? return forbidden!('Build is not erasable!') unless build.erasable?
build.erase! build.erase
present build, with: Entities::Build, present build, with: Entities::Build,
user_can_download_artifacts: can?(current_user, :download_build_artifacts, user_project) user_can_download_artifacts: can?(current_user, :download_build_artifacts, user_project)
end end
......
...@@ -170,16 +170,16 @@ describe API::API, api: true do ...@@ -170,16 +170,16 @@ describe API::API, api: true do
end end
end end
describe 'DELETE /projects/:id/builds/:build_id/content' do describe 'POST /projects/:id/builds/:build_id/erase' do
before do before do
delete api("/projects/#{project.id}/builds/#{build.id}/content", user) post api("/projects/#{project.id}/builds/#{build.id}/erase", user)
end end
context 'build is erasable' do context 'build is erasable' do
let(:build) { create(:ci_build_with_trace, :artifacts, :success, project: project, commit: commit) } let(:build) { create(:ci_build_with_trace, :artifacts, :success, project: project, commit: commit) }
it 'should erase build content' do it 'should erase build content' do
expect(response.status).to eq 200 expect(response.status).to eq 201
expect(build.trace).to be_empty expect(build.trace).to be_empty
expect(build.artifacts_file.exists?).to be_falsy expect(build.artifacts_file.exists?).to be_falsy
expect(build.artifacts_metadata.exists?).to be_falsy expect(build.artifacts_metadata.exists?).to be_falsy
......
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