Read about our upcoming Code of Conduct on this issue

This instance will be upgraded to Heptapod 0.28.1 on 2022-01-26 at 16:00 UTC+1 (a few minutes of down time)

project_path_validator.rb 743 Bytes
Newer Older
1
2
3
4
5
6
# ProjectPathValidator
#
# Custom validator for GitLab project path values.
#
# Values are checked for formatting and exclusion from a list of reserved path
# names.
7
8
9
10
11
#
# This is basically the same as the `NamespaceValidator` but it skips the validation
# of the format with `Gitlab::Regex.namespace_regex`. The format of projects
# is validated in the class itself.
class ProjectPathValidator < NamespaceValidator
12
13
14
15
  def self.valid?(value)
    !reserved?(value)
  end

16
17
  def self.reserved?(value, type: :wildcard)
    super(value, type: :wildcard)
18
19
20
21
22
23
24
25
26
27
  end

  delegate :reserved?, to: :class

  def validate_each(record, attribute, value)
    if reserved?(value)
      record.errors.add(attribute, "#{value} is a reserved name")
    end
  end
end