diff --git a/app/views/projects/builds/show.html.haml b/app/views/projects/builds/show.html.haml index ec46ce4d020ec6e5cea8cdab7f6c67fe4694440c..8eec78a557c463c8637c6ac32120bb06dc85509c 100644 --- a/app/views/projects/builds/show.html.haml +++ b/app/views/projects/builds/show.html.haml @@ -122,7 +122,7 @@ - if @build.erasable? = 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 = icon('eraser') Erase diff --git a/config/routes.rb b/config/routes.rb index 913934f7bb52a67c4a6ec6035e99e52269ae8478..c6541a8979cb42fa9f9d39a6b7439522d7ccefe8 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -617,7 +617,7 @@ Rails.application.routes.draw do get :status post :cancel post :retry - delete :erase, path: :content + post :erase end resource :artifacts, only: [] do diff --git a/doc/api/builds.md b/doc/api/builds.md index 041281311655e9c3adbfb7fd583be2c9139a5ca3..6977dedfa9e13c4f5c3edb1cfdc32534e7f01cd7 100644 --- a/doc/api/builds.md +++ b/doc/api/builds.md @@ -344,20 +344,20 @@ Example of response 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 -| Attribute | Type | required | Description | -|-----------|---------|----------|---------------------| +| Attribute | Type | required | Description | +|-------------|---------|----------|---------------------| | `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 ``` -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 diff --git a/lib/api/builds.rb b/lib/api/builds.rb index 5752ef2725bfcb7488d98c820cbdd5f464faad07..b265fa148ba76cc558fc59d19bb129364f6735fe 100644 --- a/lib/api/builds.rb +++ b/lib/api/builds.rb @@ -130,15 +130,15 @@ module API # id (required) - the id of a project # build_id (required) - the id of a build # example Request: - # delete /projects/:id/build/:build_id/content - delete ':id/builds/:build_id/content' do + # post /projects/:id/build/:build_id/erase + post ':id/builds/:build_id/erase' do authorize_update_builds! build = get_build(params[:build_id]) return not_found!(build) unless build return forbidden!('Build is not erasable!') unless build.erasable? - build.erase! + build.erase present build, with: Entities::Build, user_can_download_artifacts: can?(current_user, :download_build_artifacts, user_project) end diff --git a/spec/requests/api/builds_spec.rb b/spec/requests/api/builds_spec.rb index 0ea6c2c7356e1385cb5f3ccaeac597471c3382bc..c634bb84b773f972cf05ebbb793f837fbd364c5d 100644 --- a/spec/requests/api/builds_spec.rb +++ b/spec/requests/api/builds_spec.rb @@ -170,16 +170,16 @@ describe API::API, api: true do end end - describe 'DELETE /projects/:id/builds/:build_id/content' do + describe 'POST /projects/:id/builds/:build_id/erase' do before do - delete api("/projects/#{project.id}/builds/#{build.id}/content", user) + post api("/projects/#{project.id}/builds/#{build.id}/erase", user) end context 'build is erasable' do let(:build) { create(:ci_build_with_trace, :artifacts, :success, project: project, commit: commit) } 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.artifacts_file.exists?).to be_falsy expect(build.artifacts_metadata.exists?).to be_falsy