From 14ad75a176639ca83067ba1b45aab38ba115e5bf Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Wed, 8 Mar 2017 10:58:41 +0100 Subject: [PATCH 1/3] Fix `passed with warnings` stage status on MySQL --- app/models/ci/pipeline.rb | 2 +- app/models/ci/stage.rb | 6 +++--- spec/models/ci/pipeline_spec.rb | 18 ++++++++++++++++++ spec/models/ci/stage_spec.rb | 17 +++++++++++++---- 4 files changed, 35 insertions(+), 8 deletions(-) diff --git a/app/models/ci/pipeline.rb b/app/models/ci/pipeline.rb index 67206415f7b..8a5a9aa4adb 100644 --- a/app/models/ci/pipeline.rb +++ b/app/models/ci/pipeline.rb @@ -144,7 +144,7 @@ module Ci status_sql = statuses.latest.where('stage=sg.stage').status_sql - warnings_sql = statuses.latest.select('COUNT(*) > 0') + warnings_sql = statuses.latest.select('COUNT(*)') .where('stage=sg.stage').failed_but_allowed.to_sql stages_with_statuses = CommitStatus.from(stages_query, :sg) diff --git a/app/models/ci/stage.rb b/app/models/ci/stage.rb index ca74c91b062..b60bb9c6de0 100644 --- a/app/models/ci/stage.rb +++ b/app/models/ci/stage.rb @@ -46,10 +46,10 @@ module Ci end def has_warnings? - if @warnings.nil? - statuses.latest.failed_but_allowed.any? + if @warnings.is_a?(Fixnum) + @warnings > 0 else - @warnings + statuses.latest.failed_but_allowed.any? end end end diff --git a/spec/models/ci/pipeline_spec.rb b/spec/models/ci/pipeline_spec.rb index dd5f7098d06..3f8c24d0429 100644 --- a/spec/models/ci/pipeline_spec.rb +++ b/spec/models/ci/pipeline_spec.rb @@ -197,6 +197,24 @@ describe Ci::Pipeline, models: true do end end end + + context 'when there is a stage with warnings' do + before do + create(:commit_status, pipeline: pipeline, + stage: 'deploy', + name: 'prod:2', + stage_idx: 2, + status: 'failed', + allow_failure: true) + end + + it 'populates stage with correct number of warnings' do + deploy_stage = pipeline.stages.third + + expect(deploy_stage).not_to receive(:statuses) + expect(deploy_stage).to have_warnings + end + end end describe '#stages_count' do diff --git a/spec/models/ci/stage_spec.rb b/spec/models/ci/stage_spec.rb index c4a9743a4e2..c38faf32f7d 100644 --- a/spec/models/ci/stage_spec.rb +++ b/spec/models/ci/stage_spec.rb @@ -170,22 +170,31 @@ describe Ci::Stage, models: true do context 'when stage has warnings' do context 'when using memoized warnings flag' do context 'when there are warnings' do - let(:stage) { build(:ci_stage, warnings: true) } + let(:stage) { build(:ci_stage, warnings: 2) } - it 'has memoized warnings' do + it 'returns true using memoized value' do expect(stage).not_to receive(:statuses) expect(stage).to have_warnings end end context 'when there are no warnings' do - let(:stage) { build(:ci_stage, warnings: false) } + let(:stage) { build(:ci_stage, warnings: 0) } - it 'has memoized warnings' do + it 'returns false using memoized value' do expect(stage).not_to receive(:statuses) expect(stage).not_to have_warnings end end + + context 'when number of warnings is not a valid value' do + let(:stage) { build(:ci_stage, warnings: true) } + + it 'calculates statuses using database queries' do + expect(stage).to receive(:statuses).and_call_original + expect(stage).not_to have_warnings + end + end end context 'when calculating warnings from statuses' do From 4c2a6f0d9ce9b4c4e0f28c4e8a0232f8ca8a29e5 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Wed, 8 Mar 2017 11:02:26 +0100 Subject: [PATCH 2/3] Add changelog for passed with warnings status fix --- .../fix-gb-passed-with-warnings-status-on-mysql.yml | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 changelogs/unreleased/fix-gb-passed-with-warnings-status-on-mysql.yml diff --git a/changelogs/unreleased/fix-gb-passed-with-warnings-status-on-mysql.yml b/changelogs/unreleased/fix-gb-passed-with-warnings-status-on-mysql.yml new file mode 100644 index 00000000000..6365b1a1910 --- /dev/null +++ b/changelogs/unreleased/fix-gb-passed-with-warnings-status-on-mysql.yml @@ -0,0 +1,4 @@ +--- +title: Fix "passed with warnings" stage status on MySQL installations +merge_request: 9802 +author: From 5ca2005e0448eeeed2cab7390a89284eb0aef2e0 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Wed, 8 Mar 2017 12:34:45 +0100 Subject: [PATCH 3/3] Fix Rubocop offense in CI/CD stage code --- app/models/ci/stage.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/ci/stage.rb b/app/models/ci/stage.rb index b60bb9c6de0..e7d6b17d445 100644 --- a/app/models/ci/stage.rb +++ b/app/models/ci/stage.rb @@ -46,7 +46,7 @@ module Ci end def has_warnings? - if @warnings.is_a?(Fixnum) + if @warnings.is_a?(Integer) @warnings > 0 else statuses.latest.failed_but_allowed.any?