BigW Consortium Gitlab

regex.rb 1.7 KB
Newer Older
1 2 3 4
module Gitlab
  module Regex
    extend self

5
    def namespace_name_regex
6
      @namespace_name_regex ||= /\A[\p{Alnum}\p{Pd}_\. ]*\z/.freeze
7 8
    end

9
    def namespace_name_regex_message
10
      "can contain only letters, digits, '_', '.', dash and space."
11 12
    end

13
    def project_name_regex
14
      @project_name_regex ||= /\A[\p{Alnum}\u{00A9}-\u{1f9c0}_][\p{Alnum}\p{Pd}\u{00A9}-\u{1f9c0}_\. ]*\z/.freeze
15 16
    end

17
    def project_name_regex_message
18 19
      "can contain only letters, digits, emojis, '_', '.', dash, space. " \
      "It must start with letter, digit, emoji or '_'."
20 21
    end

Kamil Trzcinski committed
22
    def container_registry_reference_regex
23
      Gitlab::PathRegex.git_reference_regex
24
    end
25

26 27 28 29 30 31 32
    ##
    # Docker Distribution Registry 2.4.1 repository name rules
    #
    def container_repository_name_regex
      @container_repository_regex ||= %r{\A[a-z0-9]+(?:[-._/][a-z0-9]+)*\Z}
    end

Lin Jen-Shin committed
33 34 35 36
    def environment_name_regex_chars
      'a-zA-Z0-9_/\\$\\{\\}\\. -'
    end

37
    def environment_name_regex
Lin Jen-Shin committed
38
      @environment_name_regex ||= /\A[#{environment_name_regex_chars}]+\z/.freeze
39 40 41
    end

    def environment_name_regex_message
42
      "can contain only letters, digits, '-', '_', '/', '$', '{', '}', '.', and spaces"
43
    end
44 45 46 47 48 49 50 51

    def kubernetes_namespace_regex
      /\A[a-z0-9]([-a-z0-9]*[a-z0-9])?\z/
    end

    def kubernetes_namespace_regex_message
      "can contain only letters, digits or '-', and cannot start or end with '-'"
    end
Nick Thomas committed
52 53 54 55 56 57 58 59 60

    def environment_slug_regex
      @environment_slug_regex ||= /\A[a-z]([a-z0-9-]*[a-z0-9])?\z/.freeze
    end

    def environment_slug_regex_message
      "can contain only lowercase letters, digits, and '-'. " \
      "Must start with a letter, and cannot end with '-'"
    end
61 62
  end
end