Class: WebHooks::WildcardBranchFilterValidator

Inherits:
ActiveModel::EachValidator
  • Object
show all
Defined in:
app/validators/web_hooks/wildcard_branch_filter_validator.rb

Instance Method Summary collapse

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/validators/web_hooks/wildcard_branch_filter_validator.rb', line 18

def validate_each(record, attribute, value)
  value.squish! unless value.nil?

  return unless value.present?

  value_without_wildcards = value.tr('*', 'x')

  unless Gitlab::GitRefValidator.validate(value_without_wildcards)
    record.errors.add(attribute, "is not a valid branch name")
  end

  return if value.length <= 4000

  record.errors.add(attribute, "is longer than the allowed length of 4000 characters.")
end