Commit 13f92521 authored by Grzegorz Bizon's avatar Grzegorz Bizon Committed by Grzegorz Bizon

Move build eraseable API to proper API context

parent a2eac468
...@@ -115,13 +115,33 @@ module API ...@@ -115,13 +115,33 @@ module API
authorize_update_builds! authorize_update_builds!
build = get_build(params[:build_id]) build = get_build(params[:build_id])
return forbidden!('Build is not retryable') unless build && build.retryable? return not_found!(build) unless build
return forbidden!('Build is not retryable') unless build.retryable?
build = Ci::Build.retry(build) build = Ci::Build.retry(build)
present build, with: Entities::Build, present build, with: Entities::Build,
user_can_download_artifacts: can?(current_user, :read_build, user_project) user_can_download_artifacts: can?(current_user, :read_build, user_project)
end end
# Erase build (remove artifacts and build trace)
#
# Parameters:
# 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
authorize_manage_builds!
build = get_build(params[:build_id])
return not_found!(build) unless build
return forbidden!('Build is not eraseable!') unless build.eraseable?
build.erase!
present build, with: Entities::Build,
user_can_download_artifacts: can?(current_user, :download_build_artifacts, user_project)
end
end end
helpers do helpers do
......
...@@ -146,7 +146,7 @@ module Ci ...@@ -146,7 +146,7 @@ module Ci
present_file!(artifacts_file.path, artifacts_file.filename) present_file!(artifacts_file.path, artifacts_file.filename)
end end
# Remove the artifacts file from build # Remove the artifacts file from build - Runners only
# #
# Parameters: # Parameters:
# id (required) - The ID of a build # id (required) - The ID of a build
...@@ -163,23 +163,6 @@ module Ci ...@@ -163,23 +163,6 @@ module Ci
build.remove_artifacts_file! build.remove_artifacts_file!
build.remove_artifacts_metadata! build.remove_artifacts_metadata!
end end
# Erase build (remove artifacts and build trace)
#
# Parameters:
# id (required) - The ID of a build
# token (required) - The build authorization token
# Headers:
# BUILD-TOKEN (required) - The build authorization token, the same as token
# Example Request:
# DELETE /builds/:id/content
delete ':id/content' do
build = Ci::Build.find_by_id(params[:id])
not_found! unless build
authenticate_build_token!(build)
build.erase!
end
end end
end end
end end
......
...@@ -169,4 +169,29 @@ describe API::API, api: true do ...@@ -169,4 +169,29 @@ describe API::API, api: true do
end end
end end
end end
describe 'DELETE /projects/:id/builds/:build_id/content' do
before do
delete api("/projects/#{project.id}/builds/#{build.id}/content", user)
end
context 'build is eraseable' 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(build.trace).to be_empty
expect(build.artifacts_file.exists?).to be_falsy
expect(build.artifacts_metadata.exists?).to be_falsy
end
end
context 'build is not eraseable' do
let(:build) { create(:ci_build_with_trace, project: project, commit: commit) }
it 'should respond with forbidden' do
expect(response.status).to eq 403
end
end
end
end end
...@@ -156,18 +156,6 @@ describe Ci::API::API do ...@@ -156,18 +156,6 @@ describe Ci::API::API do
end end
end end
describe 'DELETE /builds/:id/content' do
let(:build) { create(:ci_build_with_trace, :artifacts, :success) }
before { delete ci_api("/builds/#{build.id}/content"), token: build.token }
it 'should erase build content' do
expect(response.status).to eq 200
expect(build.trace).to be_empty
expect(build.artifacts_file.exists?).to be_falsy
expect(build.artifacts_metadata.exists?).to be_falsy
end
end
context "Artifacts" do context "Artifacts" do
let(:file_upload) { fixture_file_upload(Rails.root + 'spec/fixtures/banana_sample.gif', 'image/gif') } let(:file_upload) { fixture_file_upload(Rails.root + 'spec/fixtures/banana_sample.gif', 'image/gif') }
let(:file_upload2) { fixture_file_upload(Rails.root + 'spec/fixtures/dk.png', 'image/gif') } let(:file_upload2) { fixture_file_upload(Rails.root + 'spec/fixtures/dk.png', 'image/gif') }
......
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