diff --git a/app/models/ci/pipeline.rb b/app/models/ci/pipeline.rb index 2ab9676c9aacf85fb0b513c70667402daf4f41fc..a00c171980e4aa1107eb3b0f7067501b9561ccc3 100644 --- a/app/models/ci/pipeline.rb +++ b/app/models/ci/pipeline.rb @@ -611,7 +611,7 @@ def cancel_running(retries: 1, cascade_to_children: true, auto_canceled_by_pipel if cascade_to_children # cancel any bridges that could spin up new child pipelines - cancel_jobs(bridges_in_self_and_descendants.cancelable, retries: retries, auto_canceled_by_pipeline_id: auto_canceled_by_pipeline_id) + cancel_jobs(bridges_in_self_and_project_descendants.cancelable, retries: retries, auto_canceled_by_pipeline_id: auto_canceled_by_pipeline_id) cancel_children(auto_canceled_by_pipeline_id: auto_canceled_by_pipeline_id, execute_async: execute_async) end end @@ -943,26 +943,26 @@ def same_family_pipeline_ids ).base_and_descendants.select(:id) end - def build_with_artifacts_in_self_and_descendants(name) - builds_in_self_and_descendants + def build_with_artifacts_in_self_and_project_descendants(name) + builds_in_self_and_project_descendants .ordered_by_pipeline # find job in hierarchical order .with_downloadable_artifacts .find_by_name(name) end - def builds_in_self_and_descendants - Ci::Build.latest.where(pipeline: self_and_descendants) + def builds_in_self_and_project_descendants + Ci::Build.latest.where(pipeline: self_and_project_descendants) end - def bridges_in_self_and_descendants - Ci::Bridge.latest.where(pipeline: self_and_descendants) + def bridges_in_self_and_project_descendants + Ci::Bridge.latest.where(pipeline: self_and_project_descendants) end - def environments_in_self_and_descendants(deployment_status: nil) + def environments_in_self_and_project_descendants(deployment_status: nil) # We limit to 100 unique environments for application safety. # See: https://gitlab.com/gitlab-org/gitlab/-/issues/340781#note_699114700 expanded_environment_names = - builds_in_self_and_descendants.joins(:metadata) + builds_in_self_and_project_descendants.joins(:metadata) .where.not('ci_builds_metadata.expanded_environment_name' => nil) .distinct('ci_builds_metadata.expanded_environment_name') .limit(100) @@ -987,7 +987,7 @@ def self_and_project_ancestors end # With only parent-child pipelines - def self_and_descendants + def self_and_project_descendants object_hierarchy(project_condition: :same).base_and_descendants end @@ -996,8 +996,8 @@ def all_child_pipelines object_hierarchy(project_condition: :same).descendants end - def self_and_descendants_complete? - self_and_descendants.all?(&:complete?) + def self_and_project_descendants_complete? + self_and_project_descendants.all?(&:complete?) end # Follow the parent-child relationships and return the top-level parent @@ -1061,8 +1061,8 @@ def latest_test_report_builds latest_report_builds(Ci::JobArtifact.of_report_type(:test)).preload(:project, :metadata) end - def latest_report_builds_in_self_and_descendants(reports_scope = ::Ci::JobArtifact.all_reports) - builds_in_self_and_descendants.with_artifacts(reports_scope) + def latest_report_builds_in_self_and_project_descendants(reports_scope = ::Ci::JobArtifact.all_reports) + builds_in_self_and_project_descendants.with_artifacts(reports_scope) end def builds_with_coverage diff --git a/app/models/environment_status.rb b/app/models/environment_status.rb index 43b2c7899a1e5b02d0f5065024c5a0c3f1bc2835..d06d0a9994842d4b0e65377b646367f4febf02eb 100644 --- a/app/models/environment_status.rb +++ b/app/models/environment_status.rb @@ -100,7 +100,7 @@ def build_change(file) def self.build_environments_status(mr, user, pipeline) return [] unless pipeline - pipeline.environments_in_self_and_descendants.includes(:project).available.map do |environment| + pipeline.environments_in_self_and_project_descendants.includes(:project).available.map do |environment| next unless Ability.allowed?(user, :read_environment, environment) EnvironmentStatus.new(pipeline.project, environment, mr, pipeline.sha) diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb index 18459805883d65f2a793932dd52f3574c75197d2..d155a295481009a59a8273d78d39cd211310285e 100644 --- a/app/models/merge_request.rb +++ b/app/models/merge_request.rb @@ -1466,7 +1466,7 @@ def mergeable_ci_state? end def environments_in_head_pipeline(deployment_status: nil) - actual_head_pipeline&.environments_in_self_and_descendants(deployment_status: deployment_status) || Environment.none + actual_head_pipeline&.environments_in_self_and_project_descendants(deployment_status: deployment_status) || Environment.none end def fetch_ref! diff --git a/app/models/project.rb b/app/models/project.rb index 78ec17acc010803323fdfd28eb1ca90324cad570..0be24252fa8d26f2d6cfebeca60cccd563bdb9d3 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -1170,7 +1170,7 @@ def latest_successful_build_for_ref(job_name, ref = default_branch) latest_pipeline = ci_pipelines.latest_successful_for_ref(ref) return unless latest_pipeline - latest_pipeline.build_with_artifacts_in_self_and_descendants(job_name) + latest_pipeline.build_with_artifacts_in_self_and_project_descendants(job_name) end def latest_successful_build_for_sha(job_name, sha) @@ -1179,7 +1179,7 @@ def latest_successful_build_for_sha(job_name, sha) latest_pipeline = ci_pipelines.latest_successful_for_sha(sha) return unless latest_pipeline - latest_pipeline.build_with_artifacts_in_self_and_descendants(job_name) + latest_pipeline.build_with_artifacts_in_self_and_project_descendants(job_name) end def latest_successful_build_for_ref!(job_name, ref = default_branch) diff --git a/app/services/ci/generate_coverage_reports_service.rb b/app/services/ci/generate_coverage_reports_service.rb index 81f26e84ef86ef66b29128d8f3f7b5b2554b0cbb..8beecb79fd9a4da69a0e6144fd072fa94f051cbe 100644 --- a/app/services/ci/generate_coverage_reports_service.rb +++ b/app/services/ci/generate_coverage_reports_service.rb @@ -43,7 +43,7 @@ def key(base_pipeline, head_pipeline) end def last_update_timestamp(pipeline_hierarchy) - pipeline_hierarchy&.self_and_descendants&.maximum(:updated_at) + pipeline_hierarchy&.self_and_project_descendants&.maximum(:updated_at) end end end diff --git a/app/workers/ci/pipeline_artifacts/coverage_report_worker.rb b/app/workers/ci/pipeline_artifacts/coverage_report_worker.rb index 127eb3b6f44155ad8a94453d7f1edfb6e51dc6e9..53bed0fa9da177c2f593786ce83a78faddab9622 100644 --- a/app/workers/ci/pipeline_artifacts/coverage_report_worker.rb +++ b/app/workers/ci/pipeline_artifacts/coverage_report_worker.rb @@ -20,7 +20,7 @@ def perform(pipeline_id) return unless pipeline pipeline.root_ancestor.try do |root_ancestor_pipeline| - next unless root_ancestor_pipeline.self_and_descendants_complete? + next unless root_ancestor_pipeline.self_and_project_descendants_complete? Ci::PipelineArtifacts::CoverageReportService.new(root_ancestor_pipeline).execute end diff --git a/lib/gitlab/ci/reports/coverage_report_generator.rb b/lib/gitlab/ci/reports/coverage_report_generator.rb index 5625707431a5a856da3de982183e58929e16c1d6..88b3b14d5c9bc2a12bd81e5bcd3151196d120010 100644 --- a/lib/gitlab/ci/reports/coverage_report_generator.rb +++ b/lib/gitlab/ci/reports/coverage_report_generator.rb @@ -35,7 +35,7 @@ def report private def report_builds - @pipeline.latest_report_builds_in_self_and_descendants(::Ci::JobArtifact.of_report_type(:coverage)) + @pipeline.latest_report_builds_in_self_and_project_descendants(::Ci::JobArtifact.of_report_type(:coverage)) end end end diff --git a/spec/models/ci/pipeline_spec.rb b/spec/models/ci/pipeline_spec.rb index c0fdf3d7d1f9493fac1add0cb5fbe1e648df7a67..84ca8ac47fe7321074a08bc3e15308983ff1f711 100644 --- a/spec/models/ci/pipeline_spec.rb +++ b/spec/models/ci/pipeline_spec.rb @@ -3629,8 +3629,8 @@ def stub_first_cancel_call_fails end end - describe '#environments_in_self_and_descendants' do - subject { pipeline.environments_in_self_and_descendants } + describe '#environments_in_self_and_project_descendants' do + subject { pipeline.environments_in_self_and_project_descendants } context 'when pipeline is not child nor parent' do let_it_be(:pipeline) { create(:ci_pipeline, :created) } @@ -4036,13 +4036,13 @@ def stub_first_cancel_call_fails end end - describe '#self_and_descendants_complete?' do + describe '#self_and_project_descendants_complete?' do let_it_be(:pipeline) { create(:ci_pipeline, :success) } let_it_be(:child_pipeline) { create(:ci_pipeline, :success, child_of: pipeline) } let_it_be_with_reload(:grandchild_pipeline) { create(:ci_pipeline, :success, child_of: child_pipeline) } context 'when all pipelines in the hierarchy is complete' do - it { expect(pipeline.self_and_descendants_complete?).to be(true) } + it { expect(pipeline.self_and_project_descendants_complete?).to be(true) } end context 'when a pipeline in the hierarchy is not complete' do @@ -4050,12 +4050,12 @@ def stub_first_cancel_call_fails grandchild_pipeline.update!(status: :running) end - it { expect(pipeline.self_and_descendants_complete?).to be(false) } + it { expect(pipeline.self_and_project_descendants_complete?).to be(false) } end end - describe '#builds_in_self_and_descendants' do - subject(:builds) { pipeline.builds_in_self_and_descendants } + describe '#builds_in_self_and_project_descendants' do + subject(:builds) { pipeline.builds_in_self_and_project_descendants } let(:pipeline) { create(:ci_pipeline) } let!(:build) { create(:ci_build, pipeline: pipeline) } @@ -4087,7 +4087,7 @@ def stub_first_cancel_call_fails end end - describe '#build_with_artifacts_in_self_and_descendants' do + describe '#build_with_artifacts_in_self_and_project_descendants' do let_it_be(:pipeline) { create(:ci_pipeline) } let!(:build) { create(:ci_build, name: 'test', pipeline: pipeline) } @@ -4095,14 +4095,14 @@ def stub_first_cancel_call_fails let!(:child_build) { create(:ci_build, :artifacts, name: 'test', pipeline: child_pipeline) } it 'returns the build with a given name, having artifacts' do - expect(pipeline.build_with_artifacts_in_self_and_descendants('test')).to eq(child_build) + expect(pipeline.build_with_artifacts_in_self_and_project_descendants('test')).to eq(child_build) end context 'when same job name is present in both parent and child pipeline' do let!(:build) { create(:ci_build, :artifacts, name: 'test', pipeline: pipeline) } it 'returns the job in the parent pipeline' do - expect(pipeline.build_with_artifacts_in_self_and_descendants('test')).to eq(build) + expect(pipeline.build_with_artifacts_in_self_and_project_descendants('test')).to eq(build) end end end @@ -4183,7 +4183,7 @@ def stub_first_cancel_call_fails end end - describe '#latest_report_builds_in_self_and_descendants' do + describe '#latest_report_builds_in_self_and_project_descendants' do let_it_be(:pipeline) { create(:ci_pipeline, project: project) } let_it_be(:child_pipeline) { create(:ci_pipeline, child_of: pipeline) } let_it_be(:grandchild_pipeline) { create(:ci_pipeline, child_of: child_pipeline) } @@ -4193,21 +4193,21 @@ def stub_first_cancel_call_fails child_build = create(:ci_build, :coverage_reports, pipeline: child_pipeline) grandchild_build = create(:ci_build, :codequality_reports, pipeline: grandchild_pipeline) - expect(pipeline.latest_report_builds_in_self_and_descendants).to contain_exactly(parent_build, child_build, grandchild_build) + expect(pipeline.latest_report_builds_in_self_and_project_descendants).to contain_exactly(parent_build, child_build, grandchild_build) end it 'filters builds by scope' do create(:ci_build, :test_reports, pipeline: pipeline) grandchild_build = create(:ci_build, :codequality_reports, pipeline: grandchild_pipeline) - expect(pipeline.latest_report_builds_in_self_and_descendants(Ci::JobArtifact.of_report_type(:codequality))).to contain_exactly(grandchild_build) + expect(pipeline.latest_report_builds_in_self_and_project_descendants(Ci::JobArtifact.of_report_type(:codequality))).to contain_exactly(grandchild_build) end it 'only returns builds that are not retried' do create(:ci_build, :codequality_reports, :retried, pipeline: grandchild_pipeline) grandchild_build = create(:ci_build, :codequality_reports, pipeline: grandchild_pipeline) - expect(pipeline.latest_report_builds_in_self_and_descendants).to contain_exactly(grandchild_build) + expect(pipeline.latest_report_builds_in_self_and_project_descendants).to contain_exactly(grandchild_build) end end diff --git a/spec/services/environments/stop_service_spec.rb b/spec/services/environments/stop_service_spec.rb index b0c9826b137c395c3b83e539337a34d51d99b2f0..4c581f31ccb80213323180f616fac18fa6421896 100644 --- a/spec/services/environments/stop_service_spec.rb +++ b/spec/services/environments/stop_service_spec.rb @@ -193,7 +193,7 @@ end it 'has active environment at first' do - expect(pipeline.environments_in_self_and_descendants.first).to be_available + expect(pipeline.environments_in_self_and_project_descendants.first).to be_available end context 'when user is a developer' do @@ -203,7 +203,7 @@ it 'stops the active environment' do subject - expect(pipeline.environments_in_self_and_descendants.first).to be_stopping + expect(pipeline.environments_in_self_and_project_descendants.first).to be_stopping end context 'when pipeline is a branch pipeline for merge request' do @@ -218,7 +218,7 @@ it 'does not stop the active environment' do subject - expect(pipeline.environments_in_self_and_descendants.first).to be_available + expect(pipeline.environments_in_self_and_project_descendants.first).to be_available end end @@ -244,7 +244,7 @@ it 'does not stop the active environment' do subject - expect(pipeline.environments_in_self_and_descendants.first).to be_available + expect(pipeline.environments_in_self_and_project_descendants.first).to be_available end end @@ -268,7 +268,7 @@ it 'does not stop the active environment' do subject - expect(pipeline.environments_in_self_and_descendants.first).to be_available + expect(pipeline.environments_in_self_and_project_descendants.first).to be_available end end end