Ignore optional actions when calculating warnings

This commit is contained in:
Grzegorz Bizon 2017-03-06 14:43:32 +01:00
parent a004a9743a
commit c4d5b231ed
3 changed files with 32 additions and 3 deletions

View file

@ -25,11 +25,13 @@ class CommitStatus < ActiveRecord::Base
end
scope :failed_but_allowed, -> do
where(allow_failure: true, status: [:failed, :canceled, :manual])
where(allow_failure: true, status: [:failed, :canceled])
end
scope :exclude_ignored, -> do
# We want to ignore failed but allowed to fail jobs
# We want to ignore failed but allowed to fail jobs.
#
# TODO, we also skip ignored optional manual actions.
where("allow_failure = ? OR status IN (?)",
false, all_state_names - [:failed, :canceled, :manual])
end

View file

@ -611,13 +611,21 @@ describe Ci::Build, :models do
it { is_expected.to be_falsey }
end
context 'and build.status is failed' do
context 'and build status is failed' do
before do
build.status = 'failed'
end
it { is_expected.to be_truthy }
end
context 'when build is a manual action' do
before do
build.status = 'manual'
end
it { is_expected.to be_falsey }
end
end
end

View file

@ -195,6 +195,25 @@ describe CommitStatus, :models do
end
end
describe '.failed_but_allowed' do
subject { described_class.failed_but_allowed.order(:id) }
let(:statuses) do
[create_status(allow_failure: true, status: 'success'),
create_status(allow_failure: true, status: 'failed'),
create_status(allow_failure: false, status: 'success'),
create_status(allow_failure: false, status: 'failed'),
create_status(allow_failure: true, status: 'canceled'),
create_status(allow_failure: false, status: 'canceled'),
create_status(allow_failure: true, status: 'manual'),
create_status(allow_failure: false, status: 'manual')]
end
it 'returns statuses without what we want to ignore' do
is_expected.to eq(statuses.values_at(1, 4))
end
end
describe '#before_sha' do
subject { commit_status.before_sha }