BigW Consortium Gitlab

regex.rb 2.1 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

22
    ##
23 24 25
    # Docker Distribution Registry repository / tag name rules
    #
    # See https://github.com/docker/distribution/blob/master/reference/regexp.go.
26 27
    #
    def container_repository_name_regex
28
      @container_repository_regex ||= %r{\A[a-z0-9]+((?:[._/]|__|[-])[a-z0-9]+)*\Z}
29 30
    end

31 32 33 34
    ##
    # We do not use regexp anchors here because these are not allowed when
    # used as a routing constraint.
    #
35 36 37 38
    def container_registry_tag_regex
      @container_registry_tag_regex ||= /[\w][\w.-]{0,127}/
    end

Lin Jen-Shin committed
39 40 41 42
    def environment_name_regex_chars
      'a-zA-Z0-9_/\\$\\{\\}\\. -'
    end

43
    def environment_name_regex
Lin Jen-Shin committed
44
      @environment_name_regex ||= /\A[#{environment_name_regex_chars}]+\z/.freeze
45 46 47
    end

    def environment_name_regex_message
48
      "can contain only letters, digits, '-', '_', '/', '$', '{', '}', '.', and spaces"
49
    end
50 51 52 53 54 55

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

    def kubernetes_namespace_regex_message
56 57
      "can contain only lowercase letters, digits, and '-'. " \
      "Must start with a letter, and cannot end with '-'"
58
    end
Nick Thomas committed
59 60 61 62 63 64 65 66 67

    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
68 69 70 71

    def build_trace_section_regex
      @build_trace_section_regexp ||= /section_((?:start)|(?:end)):(\d+):([^\r]+)\r\033\[0K/.freeze
    end
72 73
  end
end