Commit 9974d366 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Merge branch 'make-ci-composite-status-to-be-project-scoped' into 'master'

Make `ci_composite_status` project scoped

See merge request gitlab-org/gitlab!28653
parents 75c603a2 9cd68086
...@@ -32,7 +32,7 @@ module Ci ...@@ -32,7 +32,7 @@ module Ci
end end
def status def status
@status ||= statuses.latest.slow_composite_status @status ||= statuses.latest.slow_composite_status(project: project)
end end
def detailed_status(current_user) def detailed_status(current_user)
......
...@@ -968,7 +968,7 @@ module Ci ...@@ -968,7 +968,7 @@ module Ci
def latest_builds_status def latest_builds_status
return 'failed' unless yaml_errors.blank? return 'failed' unless yaml_errors.blank?
statuses.latest.slow_composite_status || 'skipped' statuses.latest.slow_composite_status(project: project) || 'skipped'
end end
def keep_around_commits def keep_around_commits
......
...@@ -138,7 +138,7 @@ module Ci ...@@ -138,7 +138,7 @@ module Ci
end end
def latest_stage_status def latest_stage_status
statuses.latest.slow_composite_status || 'skipped' statuses.latest.slow_composite_status(project: project) || 'skipped'
end end
end end
end end
...@@ -178,12 +178,12 @@ class CommitStatus < ApplicationRecord ...@@ -178,12 +178,12 @@ class CommitStatus < ApplicationRecord
select(:name) select(:name)
end end
def self.status_for_prior_stages(index) def self.status_for_prior_stages(index, project:)
before_stage(index).latest.slow_composite_status || 'success' before_stage(index).latest.slow_composite_status(project: project) || 'success'
end end
def self.status_for_names(names) def self.status_for_names(names, project:)
where(name: names).latest.slow_composite_status || 'success' where(name: names).latest.slow_composite_status(project: project) || 'success'
end end
def self.update_as_processed! def self.update_as_processed!
......
...@@ -65,8 +65,8 @@ module HasStatus ...@@ -65,8 +65,8 @@ module HasStatus
# This method performs expensive calculation of status: # This method performs expensive calculation of status:
# 1. By plucking all related objects, # 1. By plucking all related objects,
# 2. Or executes expensive SQL query # 2. Or executes expensive SQL query
def slow_composite_status def slow_composite_status(project:)
if Feature.enabled?(:ci_composite_status, default_enabled: false) if Feature.enabled?(:ci_composite_status, project, default_enabled: false)
Gitlab::Ci::Status::Composite Gitlab::Ci::Status::Composite
.new(all, with_allow_failure: columns_hash.key?('allow_failure')) .new(all, with_allow_failure: columns_hash.key?('allow_failure'))
.status .status
......
...@@ -89,11 +89,11 @@ module Ci ...@@ -89,11 +89,11 @@ module Ci
end end
def status_for_prior_stages(index) def status_for_prior_stages(index)
pipeline.processables.status_for_prior_stages(index) pipeline.processables.status_for_prior_stages(index, project: pipeline.project)
end end
def status_for_build_needs(needs) def status_for_build_needs(needs)
pipeline.processables.status_for_names(needs) pipeline.processables.status_for_names(needs, project: pipeline.project)
end end
# rubocop: disable CodeReuse/ActiveRecord # rubocop: disable CodeReuse/ActiveRecord
......
...@@ -1924,7 +1924,7 @@ describe Ci::Pipeline, :mailer do ...@@ -1924,7 +1924,7 @@ describe Ci::Pipeline, :mailer do
describe '#update_status' do describe '#update_status' do
context 'when pipeline is empty' do context 'when pipeline is empty' do
it 'updates does not change pipeline status' do it 'updates does not change pipeline status' do
expect(pipeline.statuses.latest.slow_composite_status).to be_nil expect(pipeline.statuses.latest.slow_composite_status(project: project)).to be_nil
expect { pipeline.update_legacy_status } expect { pipeline.update_legacy_status }
.to change { pipeline.reload.status } .to change { pipeline.reload.status }
......
...@@ -423,7 +423,7 @@ describe CommitStatus do ...@@ -423,7 +423,7 @@ describe CommitStatus do
end end
it 'returns a correct compound status' do it 'returns a correct compound status' do
expect(described_class.all.slow_composite_status).to eq 'running' expect(described_class.all.slow_composite_status(project: project)).to eq 'running'
end end
end end
...@@ -433,7 +433,7 @@ describe CommitStatus do ...@@ -433,7 +433,7 @@ describe CommitStatus do
end end
it 'returns status that indicates success' do it 'returns status that indicates success' do
expect(described_class.all.slow_composite_status).to eq 'success' expect(described_class.all.slow_composite_status(project: project)).to eq 'success'
end end
end end
...@@ -444,7 +444,7 @@ describe CommitStatus do ...@@ -444,7 +444,7 @@ describe CommitStatus do
end end
it 'returns status according to the scope' do it 'returns status according to the scope' do
expect(described_class.latest.slow_composite_status).to eq 'success' expect(described_class.latest.slow_composite_status(project: project)).to eq 'success'
end end
end end
end end
......
...@@ -6,7 +6,7 @@ describe HasStatus do ...@@ -6,7 +6,7 @@ describe HasStatus do
describe '.slow_composite_status' do describe '.slow_composite_status' do
using RSpec::Parameterized::TableSyntax using RSpec::Parameterized::TableSyntax
subject { CommitStatus.slow_composite_status } subject { CommitStatus.slow_composite_status(project: nil) }
shared_examples 'build status summary' do shared_examples 'build status summary' do
context 'all successful' do context 'all successful' do
......
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