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

Merge branch 'update-include-rules-exists-limit' into 'master'

Disable 50-path limit on `include:rules:exist` in new feature code

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



Merged-by: default avatarLaura Montemayor <lmontemayor@gitlab.com>
Approved-by: default avatarLaura Montemayor <lmontemayor@gitlab.com>
Approved-by: default avatarAvielle Wolfe <awolfe@gitlab.com>
Co-authored-by: default avatarlma-git <lma@gitlab.com>
No related branches found
No related tags found
无相关合并请求
......@@ -19,8 +19,10 @@ class Rules::Rule < ::Gitlab::Config::Entry::Node
entry :changes, Entry::Rules::Rule::Changes,
description: 'File change condition rule.'
# TODO: Remove `disable_simple_exists_paths_limit` in https://gitlab.com/gitlab-org/gitlab/-/issues/456276.
entry :exists, Entry::Rules::Rule::Exists,
description: 'File exists condition rule.'
description: 'File exists condition rule.',
metadata: { disable_simple_exists_paths_limit: true }
validations do
validates :config, presence: true
......
......@@ -7,6 +7,8 @@ module Entry
class Rules
class Rule
class Exists < ::Gitlab::Config::Entry::Simplifiable
MAX_PATHS = 50
# TODO: We should not have the String support for `exists`.
# Issue to remove: https://gitlab.com/gitlab-org/gitlab/-/issues/455040
strategy :SimpleExists, if: ->(config) { config.is_a?(String) || config.is_a?(Array) || config.blank? }
......@@ -16,9 +18,12 @@ class SimpleExists < ::Gitlab::Config::Entry::Node
include ::Gitlab::Config::Entry::Validatable
validations do
# TODO: Enforce 50-path limit in https://gitlab.com/gitlab-org/gitlab/-/issues/456276.
validates :config, array_of_strings: true,
length: { maximum: MAX_PATHS, too_long: 'has too many entries (maximum %{count})' },
if: -> { config.is_a?(Array) && !opt(:disable_simple_exists_paths_limit) }
validates :config, array_of_strings: true,
length: { maximum: 50, too_long: 'has too many entries (maximum %{count})' },
if: -> { config.is_a?(Array) }
if: -> { config.is_a?(Array) && opt(:disable_simple_exists_paths_limit) }
end
def value
......@@ -42,7 +47,7 @@ class ComplexExists < ::Gitlab::Config::Entry::Node
with_options allow_nil: true do
validates :paths, array_of_strings: true,
length: { maximum: 50, too_long: 'has too many entries (maximum %{count})' }
length: { maximum: MAX_PATHS, too_long: 'has too many entries (maximum %{count})' }
validates :project, type: String
validates :ref, type: String
end
......
......@@ -109,6 +109,18 @@
it_behaves_like 'a valid config', { exists: { paths: [] } }
end
context 'when array contains integers' do
let(:config) { { exists: [1, 2, 3] } }
it_behaves_like 'an invalid config', /should be an array of strings/
end
context 'when array has more items than MAX_PATHS' do
let(:config) { { exists: ['app/*'] * 51 } }
it_behaves_like 'a valid config', { exists: { paths: ['app/*'] * 51 } }
end
end
context 'with a hash' do
......@@ -167,6 +179,18 @@
it_behaves_like 'a valid config'
end
context 'when exists: clause is an array of integers' do
let(:config) { { exists: [1, 2, 3] } }
it_behaves_like 'an invalid config', /should be an array of strings or a string/
end
context 'when exists: clause has more items than MAX_PATHS' do
let(:config) { { exists: ['app/*'] * 51 } }
it_behaves_like 'a valid config'
end
context 'when exists: clause is null' do
let(:config) { { exists: nil } }
......
......@@ -4,9 +4,13 @@
RSpec.describe Gitlab::Ci::Config::Entry::Rules::Rule::Exists, feature_category: :pipeline_composition do
let(:factory) do
Gitlab::Config::Entry::Factory.new(described_class).value(config)
Gitlab::Config::Entry::Factory.new(described_class)
.metadata(metadata)
.value(config)
end
let(:metadata) { {} }
subject(:entry) { factory.create! }
before do
......@@ -65,6 +69,12 @@
is_expected.not_to be_valid
expect(entry.errors).to include(/has too many entries \(maximum 50\)/)
end
context 'when opt(:disable_simple_exists_paths_limit) is true' do
let(:metadata) { { disable_simple_exists_paths_limit: true } }
it_behaves_like 'a valid config', { paths: ['**/test.md'] * 51 }
end
end
end
......
......@@ -175,6 +175,24 @@
it { is_expected.to be_valid }
end
context 'when array contains integers' do
let(:config) { { exists: [1, 2, 3] } }
it 'returns an error' do
is_expected.not_to be_valid
expect(entry.errors).to include(/should be an array of strings/)
end
end
context 'when array has more items than MAX_PATHS' do
let(:config) { { exists: ['app/*'] * 51 } }
it 'returns an error' do
is_expected.not_to be_valid
expect(entry.errors).to include(/has too many entries \(maximum 50\)/)
end
end
end
context 'with a hash' do
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册