Find a better place for the PipelineExecutionPolicy class/struct
Summary
In !158198 (merged) and !151339 (merged), we decided to have a "carrier" class/struct for pipeline execution policies that will store the created pipeline and some attributes of the policy.
For now, we added this into ee/lib/ee/gitlab/ci/pipeline/chain/pipeline_execution_policies/find_configs.rb but maybe there is a better way to handle this. We also use it in ee/spec/factories/ci/pipeline_execution_policy.rb.
PipelineExecutionPolicy = Struct.new(:pipeline, :strategy) do
def strategy_override_project_ci?
strategy == :override_project_ci
end
end
Implementation plan
We can move the struct into the Gitlab::Ci::Pipeline::Chain namespace to its own class. This would match the pattern we already use with Gitlab::Ci::Pipeline::Chain::Command
diff --git a/ee/lib/ee/gitlab/ci/pipeline/chain/pipeline_execution_policies/find_configs.rb b/ee/lib/ee/gitlab/ci/pipeline/chain/pipeline_execution_policies/find_configs.rb
index 31b10d7d3adb..bdf684294c80 100644
--- a/ee/lib/ee/gitlab/ci/pipeline/chain/pipeline_execution_policies/find_configs.rb
+++ b/ee/lib/ee/gitlab/ci/pipeline/chain/pipeline_execution_policies/find_configs.rb
@@ -24,12 +24,6 @@ module FindConfigs
include ::Gitlab::Utils::StrongMemoize
extend ::Gitlab::Utils::Override
- PipelineExecutionPolicy = Struct.new(:pipeline, :strategy) do
- def strategy_override_project_ci?
- strategy == :override_project_ci
- end
- end
-
override :perform!
def perform!
return if ::Feature.disabled?(:pipeline_execution_policy_type, project.group)
@@ -43,7 +37,7 @@ def perform!
pipeline = response.payload
if response.success?
- command.pipeline_execution_policies << PipelineExecutionPolicy.new(pipeline, config.strategy)
+ command.pipeline_execution_policies << ::Gitlab::Ci::Pipeline::Chain::PipelineExecutionPolicy.new(pipeline, config.strategy)
elsif pipeline.filtered_as_empty?
# no-op: we ignore empty pipelines
else
diff --git a/ee/spec/factories/ci/pipeline_execution_policy.rb b/ee/spec/factories/ci/pipeline_execution_policy.rb
index c237053d152c..d623cc6a7fb5 100644
--- a/ee/spec/factories/ci/pipeline_execution_policy.rb
+++ b/ee/spec/factories/ci/pipeline_execution_policy.rb
@@ -3,7 +3,7 @@
FactoryBot.define do
factory(
:ci_pipeline_execution_policy,
- class: '::Gitlab::Ci::Pipeline::Chain::PipelineExecutionPolicies::FindConfigs::PipelineExecutionPolicy'
+ class: '::Gitlab::Ci::Pipeline::Chain::PipelineExecutionPolicy'
) do
pipeline factory: :ci_empty_pipeline
strategy { :inject_ci }
Edited by Andy Schoenen