Commit 6113ff99 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Expose stage model attributes from pipeline object

parent 96cd4228
...@@ -292,6 +292,16 @@ module Ci ...@@ -292,6 +292,16 @@ module Ci
sort_by { |build| build[:stage_idx] } sort_by { |build| build[:stage_idx] }
end end
def config_stages_attributes
return [] unless config_processor
config_processor.stages_for_ref(ref, tag?, trigger_requests.first)
end
def has_stages?
config_stages_attributes.any?
end
def has_warnings? def has_warnings?
builds.latest.failed_but_allowed.any? builds.latest.failed_but_allowed.any?
end end
......
...@@ -42,8 +42,8 @@ module Ci ...@@ -42,8 +42,8 @@ module Ci
return pipeline return pipeline
end end
unless pipeline.config_builds_attributes.present? unless pipeline.has_stages?
return error('No builds for this pipeline.') return error('No stages / jobs for this pipeline.')
end end
Ci::Pipeline.transaction do Ci::Pipeline.transaction do
......
...@@ -502,6 +502,20 @@ describe Ci::Pipeline, models: true do ...@@ -502,6 +502,20 @@ describe Ci::Pipeline, models: true do
end end
end end
describe '#has_stages?' do
context 'when pipeline has stages' do
subject { create(:ci_pipeline_with_one_job) }
it { is_expected.to have_stages }
end
context 'when pipeline does not have stages' do
subject { create(:ci_pipeline_without_jobs) }
it { is_expected.not_to have_stages }
end
end
describe '#has_warnings?' do describe '#has_warnings?' do
subject { pipeline.has_warnings? } subject { pipeline.has_warnings? }
......
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