diff options
author | Kamil Trzcinski <ayufan@ayufan.eu> | 2017-02-06 16:06:44 +0100 |
---|---|---|
committer | Kamil Trzcinski <ayufan@ayufan.eu> | 2017-02-06 16:06:44 +0100 |
commit | a8825f0c7fb5da6a047813a491e6b8aebc33bb5b (patch) | |
tree | 4b676823f617ae696b11f606272c139d7007960b /app/models/environment.rb | |
parent | 3cd17c9430c7575b0c1f1041947f3cd0d991f00c (diff) | |
parent | e438b30a315e092e03afa9d84f8a9e57ded3b0a2 (diff) | |
download | gitlab-ce-a8825f0c7fb5da6a047813a491e6b8aebc33bb5b.tar.gz |
Merge remote-tracking branch 'origin/master' into 24147-delete-env-button
Diffstat (limited to 'app/models/environment.rb')
-rw-r--r-- | app/models/environment.rb | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/app/models/environment.rb b/app/models/environment.rb index 8bca47373f8..066f57292b8 100644 --- a/app/models/environment.rb +++ b/app/models/environment.rb @@ -1,7 +1,8 @@ class Environment < ActiveRecord::Base # Used to generate random suffixes for the slug + LETTERS = 'a'..'z' NUMBERS = '0'..'9' - SUFFIX_CHARS = ('a'..'z').to_a + NUMBERS.to_a + SUFFIX_CHARS = LETTERS.to_a + NUMBERS.to_a belongs_to :project, required: true, validate: true @@ -148,17 +149,24 @@ class Environment < ActiveRecord::Base slugified = name.to_s.downcase.gsub(/[^a-z0-9]/, '-') # Must start with a letter - slugified = "env-" + slugified if NUMBERS.cover?(slugified[0]) + slugified = 'env-' + slugified unless LETTERS.cover?(slugified[0]) + + # Repeated dashes are invalid (OpenShift limitation) + slugified.gsub!(/\-+/, '-') # Maximum length: 24 characters (OpenShift limitation) slugified = slugified[0..23] - # Cannot end with a "-" character (Kubernetes label limitation) - slugified = slugified[0..-2] if slugified[-1] == "-" + # Cannot end with a dash (Kubernetes label limitation) + slugified.chop! if slugified.end_with?('-') # Add a random suffix, shortening the current string if necessary, if it # has been slugified. This ensures uniqueness. - slugified = slugified[0..16] + "-" + random_suffix if slugified != name + if slugified != name + slugified = slugified[0..16] + slugified << '-' unless slugified.end_with?('-') + slugified << random_suffix + end self.slug = slugified end |