Skip to content
代码片段 群组 项目
未验证 提交 099dd959 编辑于 作者: Furkan Ayhan's avatar Furkan Ayhan 提交者: GitLab
浏览文件

Merge branch '494431-fix-stages-compatible' into 'master'

Fix stages_compatible? not being restrictive enough

See merge request https://gitlab.com/gitlab-org/gitlab/-/merge_requests/173273



Merged-by: default avatarFurkan Ayhan <furkanayhn@gmail.com>
Approved-by: default avatarFurkan Ayhan <furkanayhn@gmail.com>
Reviewed-by: default avatarAndy Schoenen <asoiron@gitlab.com>
Reviewed-by: default avatarFurkan Ayhan <furkanayhn@gmail.com>
Reviewed-by: default avatarMartin Čavoj <mcavoj@gitlab.com>
Co-authored-by: default avatarMartin Čavoj <mcavoj@gitlab.com>
No related branches found
No related tags found
无相关合并请求
......@@ -52,7 +52,7 @@ def has_overriding_execution_policy_pipelines?
policy_pipelines.any?(&:strategy_override_project_ci?)
end
def collect_declared_stages!(stages)
def collect_declared_stages!(new_stages)
return unless creating_policy_pipeline?
return unless current_policy.strategy_override_project_ci?
......@@ -61,12 +61,12 @@ def collect_declared_stages!(stages)
"Its stages are incompatible with stages of another `override_project_ci` policy: " \
"#{override_policy_stages.join(', ')}.")
if stages.size > override_policy_stages.size
raise error unless stages_compatible?(override_policy_stages, stages)
if new_stages.size > override_policy_stages.size
raise error unless stages_compatible?(override_policy_stages, new_stages)
@override_policy_stages = stages
@override_policy_stages = new_stages
else
raise error unless stages_compatible?(stages, override_policy_stages)
raise error unless stages_compatible?(new_stages, override_policy_stages)
end
end
......@@ -120,19 +120,17 @@ def with_policy_context(policy)
end
end
# `current_stages` are considered compatible if they are an ordered subset of `target_stages`.
# `target_stages` s larger or equally large set of stages.
# Elements of `current_stages` must appear in the same order as in `target_stages`.
# `stages` are considered compatible if they are an ordered subset of `target_stages`.
# `target_stages` is larger or equally large set of stages.
# Elements of `stages` must appear in the same order as in `target_stages`.
# Valid example:
# `current_stages`: [build, deploy]
# `stages`: [build, deploy]
# `target_stages`: [build, test, deploy]
# Invalid example:
# `current_stages`: [deploy, build]
# `stages`: [deploy, build]
# `target_stages`: [build, test, deploy]
def stages_compatible?(current_stages, target_stages)
return true if current_stages.blank? || current_stages == target_stages
current_stages.each_with_index.all? { |stage, index| target_stages[index..].include?(stage) }
def stages_compatible?(stages, target_stages)
stages == target_stages & stages
end
end
end
......
......@@ -303,6 +303,7 @@
%w[build deploy] | %w[deploy test build]
%w[deploy test build] | %w[build deploy]
%w[deploy test build] | %w[build other]
%w[deploy test] | %w[build policy-build test policy-test deploy]
end
with_them do
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册