Commit c8102d93 authored by Grzegorz Bizon's avatar Grzegorz Bizon Committed by Grzegorz Bizon
Browse files

Add build eraseable feature implementation

parent 89b18120
......@@ -56,10 +56,10 @@ def status
render json: @build.to_json(only: [:status, :id, :sha, :coverage], methods: :sha)
end
def destroy
@build.destroy
redirect_to namespace_project_builds_path(project.namespace, project),
notice: "Build ##{@build.id} has been sucessfully removed!"
def erase
@build.erase!
redirect_to namespace_project_build_path(project.namespace, project, @build),
notice: "Build ##{@build.id} has been sucessfully erased!"
end
private
......
......@@ -4,11 +4,26 @@ module Eraseable
include ActiveSupport::Concern
def erase!
raise NotImplementedError
raise StandardError, 'Build not eraseable!' unless eraseable?
remove_artifacts_file!
remove_artifacts_metadata!
erase_trace!
end
def erased?
raise NotImpementedError
def eraseable?
artifacts_file.exists? || File.file?(path_to_trace)
end
def erase_url
if eraseable?
erase_namespace_project_build_path(project.namespace, project, self)
end
end
private
def erase_trace!
File.truncate(path_to_trace, 0) if File.file?(path_to_trace)
end
end
end
......
......@@ -113,10 +113,11 @@
- elsif @build.retry_url
= link_to "Retry", @build.retry_url, class: 'btn btn-sm btn-primary', method: :post
= link_to '', class: 'btn btn-sm btn-danger', method: :delete,
data: { confirm: 'Are you sure you want to remove this?' } do
= icon('remove')
Remove
- if @build.eraseable?
= link_to @build.erase_url, class: 'btn btn-sm btn-warning', method: :put,
data: { confirm: 'Are you sure you want to erase this build?' } do
= icon('eraser')
Erase
.clearfix
- if @build.duration
......
......@@ -617,6 +617,7 @@
get :status
post :cancel
post :retry
put :erase
end
resource :artifacts, only: [] do
......
require 'spec_helper'
describe Ci::Build::Eraseable, models: true do
context 'build is not eraseable' do
let!(:build) { create(:ci_build) }
describe '#erase!' do
it { expect { build.erase! }.to raise_error(StandardError, /Build not eraseable!/ )}
end
describe '#eraseable?' do
subject { build.eraseable? }
it { is_expected.to eq false }
end
describe '#erase_url' do
subject { build.erase_url }
it { is_expected.to be_falsy }
end
end
context 'build is eraseable' do
let!(:build) { create(:ci_build_with_trace, :artifacts) }
describe '#erase!' do
before { build.erase! }
it 'should remove artifact file' do
expect(build.artifacts_file.exists?).to be_falsy
end
it 'should remove artifact metadata file' do
expect(build.artifacts_metadata.exists?).to be_falsy
end
it 'should erase build trace in trace file' do
expect(File.zero?(build.path_to_trace)).to eq true
end
end
describe '#eraseable?' do
subject { build.eraseable? }
it { is_expected.to eq true }
end
describe '#erase_url' do
subject { build.erase_url }
it { is_expected.to be_truthy }
end
context 'metadata and build trace are not available' do
let!(:build) { create(:ci_build, :artifacts) }
before { build.remove_artifacts_metadata! }
describe '#erase!' do
it 'should not raise error' do
expect { build.erase! }.to_not raise_error
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