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