Skip to content
Snippets Groups Projects
Commit 8403991c authored by Shinya Maeda's avatar Shinya Maeda
Browse files

Fix related environments on pipeline

This commit fixes the database query to fetch
related environments of a pipeline.

The feature is still behind a feature flag.
parent 447acc66
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -957,7 +957,7 @@ def environments_in_self_and_descendants
.limit(100)
.pluck(:expanded_environment_name)
 
Environment.where(project: project, name: expanded_environment_names)
Environment.where(project: project, name: expanded_environment_names).with_deployments
else
environment_ids = self_and_descendants.joins(:deployments).select(:'deployments.environment_id')
 
Loading
Loading
Loading
Loading
@@ -89,6 +89,7 @@ class Environment < ApplicationRecord
 
scope :for_project, -> (project) { where(project_id: project) }
scope :for_tier, -> (tier) { where(tier: tier).where.not(tier: nil) }
scope :with_deployments, -> { where('EXISTS (?)', Deployment.select(1).where('deployments.environment_id = environments.id')) }
scope :with_deployment, -> (sha) { where('EXISTS (?)', Deployment.select(1).where('deployments.environment_id = environments.id').where(sha: sha)) }
scope :unfoldered, -> { where(environment_type: nil) }
scope :with_rank, -> do
Loading
Loading
Loading
Loading
@@ -3180,6 +3180,20 @@ def create_pipeline(status, ref, sha)
end
end
 
context 'when an associated environment does not have deployments' do
let_it_be(:pipeline) { create(:ci_pipeline, :created) }
let_it_be(:build) { create(:ci_build, :stop_review_app, pipeline: pipeline) }
let_it_be(:environment) { create(:environment, project: pipeline.project) }
before_all do
build.metadata.update!(expanded_environment_name: environment.name)
end
it 'does not return environments' do
expect(subject).to be_empty
end
end
context 'when pipeline is in extended family' do
let_it_be(:parent) { create(:ci_pipeline) }
let_it_be(:parent_build) { create(:ci_build, :with_deployment, environment: 'staging', pipeline: parent) }
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment