Commit 8dbd1e7d authored by Grzegorz Bizon's avatar Grzegorz Bizon

Add concrete success warning status to stage factory

parent 8b30dd98
...@@ -39,5 +39,13 @@ module Ci ...@@ -39,5 +39,13 @@ module Ci
def builds def builds
@builds ||= pipeline.builds.where(stage: name) @builds ||= pipeline.builds.where(stage: name)
end end
def success?
status.to_s == 'success'
end
def has_warnings?
statuses.latest.failed_but_allowed.any?
end
end end
end end
...@@ -4,7 +4,7 @@ module Gitlab ...@@ -4,7 +4,7 @@ module Gitlab
module Pipeline module Pipeline
class Factory < Status::Factory class Factory < Status::Factory
def self.extended_statuses def self.extended_statuses
[Pipeline::SuccessWarning] [Status::SuccessWarning]
end end
def self.common_helpers def self.common_helpers
......
module Gitlab
module Ci
module Status
module Pipeline
class SuccessWarning < Status::SuccessWarning
def self.matches?(pipeline, user)
pipeline.success? && pipeline.has_warnings?
end
end
end
end
end
end
...@@ -3,6 +3,10 @@ module Gitlab ...@@ -3,6 +3,10 @@ module Gitlab
module Status module Status
module Stage module Stage
class Factory < Status::Factory class Factory < Status::Factory
def self.extended_statuses
[Status::SuccessWarning]
end
def self.common_helpers def self.common_helpers
Status::Stage::Common Status::Stage::Common
end end
......
...@@ -2,9 +2,7 @@ module Gitlab ...@@ -2,9 +2,7 @@ module Gitlab
module Ci module Ci
module Status module Status
## ##
# Abstract extended status used when pipeline/stage/build passed # Extended status used when pipeline or stage passed conditionally.
# conditionally.
#
# This means that failed jobs that are allowed to fail were present. # This means that failed jobs that are allowed to fail were present.
# #
class SuccessWarning < SimpleDelegator class SuccessWarning < SimpleDelegator
...@@ -27,7 +25,7 @@ module Gitlab ...@@ -27,7 +25,7 @@ module Gitlab
end end
def self.matches?(subject, user) def self.matches?(subject, user)
raise NotImplementedError subject.success? && subject.has_warnings?
end end
end end
end end
......
...@@ -49,11 +49,12 @@ describe Gitlab::Ci::Status::Pipeline::Factory do ...@@ -49,11 +49,12 @@ describe Gitlab::Ci::Status::Pipeline::Factory do
it 'fabricates extended "success with warnings" status' do it 'fabricates extended "success with warnings" status' do
expect(status) expect(status)
.to be_a Gitlab::Ci::Status::Pipeline::SuccessWarning .to be_a Gitlab::Ci::Status::SuccessWarning
end end
it 'extends core status with common pipeline methods' do it 'extends core status with common pipeline method' do
expect(status).to have_details expect(status).to have_details
expect(status.details_path).to include "pipelines/#{pipeline.id}"
end end
end end
end end
...@@ -42,5 +42,27 @@ describe Gitlab::Ci::Status::Stage::Factory do ...@@ -42,5 +42,27 @@ describe Gitlab::Ci::Status::Stage::Factory do
end end
end end
end end
end
context 'when stage has warnings' do
let(:stage) do
build(:ci_stage, name: 'test', status: :success, pipeline: pipeline)
end
before do
create(:ci_build, :allowed_to_fail, :failed,
stage: 'test', pipeline: stage.pipeline)
end
it 'fabricates extended "success with warnings" status' do
expect(status)
.to be_a Gitlab::Ci::Status::SuccessWarning
end
it 'extends core status with common stage method' do
expect(status).to have_details
expect(status.details_path).to include "pipelines/#{pipeline.id}##{stage.name}"
end
end end
end end
require 'spec_helper' require 'spec_helper'
describe Gitlab::Ci::Status::Pipeline::SuccessWarning do describe Gitlab::Ci::Status::SuccessWarning do
subject do subject do
described_class.new(double('status')) described_class.new(double('status'))
end end
...@@ -22,46 +22,52 @@ describe Gitlab::Ci::Status::Pipeline::SuccessWarning do ...@@ -22,46 +22,52 @@ describe Gitlab::Ci::Status::Pipeline::SuccessWarning do
end end
describe '.matches?' do describe '.matches?' do
context 'when pipeline is successful' do let(:matchable) { double('matchable') }
let(:pipeline) do
create(:ci_pipeline, status: :success) context 'when matchable subject is successful' do
before do
allow(matchable).to receive(:success?).and_return(true)
end end
context 'when pipeline has warnings' do context 'when matchable subject has warnings' do
before do before do
allow(pipeline).to receive(:has_warnings?).and_return(true) allow(matchable).to receive(:has_warnings?).and_return(true)
end end
it 'is a correct match' do it 'is a correct match' do
expect(described_class.matches?(pipeline, double)).to eq true expect(described_class.matches?(matchable, double)).to eq true
end
end end
context 'when matchable subject does not have warnings' do
before do
allow(matchable).to receive(:has_warnings?).and_return(false)
end end
context 'when pipeline does not have warnings' do
it 'does not match' do it 'does not match' do
expect(described_class.matches?(pipeline, double)).to eq false expect(described_class.matches?(matchable, double)).to eq false
end end
end end
end end
context 'when pipeline is not successful' do context 'when matchable subject is not successful' do
let(:pipeline) do before do
create(:ci_pipeline, status: :skipped) allow(matchable).to receive(:success?).and_return(false)
end end
context 'when pipeline has warnings' do context 'when matchable subject has warnings' do
before do before do
allow(pipeline).to receive(:has_warnings?).and_return(true) allow(matchable).to receive(:has_warnings?).and_return(true)
end end
it 'does not match' do it 'does not match' do
expect(described_class.matches?(pipeline, double)).to eq false expect(described_class.matches?(matchable, double)).to eq false
end end
end end
context 'when pipeline does not have warnings' do context 'when matchable subject does not have warnings' do
it 'does not match' do it 'does not match' do
expect(described_class.matches?(pipeline, double)).to eq false expect(described_class.matches?(matchable, double)).to eq false
end 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