BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
e806bdaf
Commit
e806bdaf
authored
Jan 19, 2017
by
Nick Thomas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Avoid repeated dashes in $CI_ENVIRONMENT_SLUG
parent
2de5f511
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
35 additions
and
10 deletions
+35
-10
environment.rb
app/models/environment.rb
+13
-5
26852-fix-slug-for-openshift.yml
changelogs/unreleased/26852-fix-slug-for-openshift.yml
+4
-0
20161207231626_add_environment_slug.rb
db/migrate/20161207231626_add_environment_slug.rb
+13
-5
environment_spec.rb
spec/models/environment_spec.rb
+5
-0
No files found.
app/models/environment.rb
View file @
e806bdaf
class
Environment
<
ActiveRecord
::
Base
class
Environment
<
ActiveRecord
::
Base
# Used to generate random suffixes for the slug
# Used to generate random suffixes for the slug
LETTERS
=
'a'
..
'z'
NUMBERS
=
'0'
..
'9'
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
belongs_to
:project
,
required:
true
,
validate:
true
...
@@ -148,17 +149,24 @@ class Environment < ActiveRecord::Base
...
@@ -148,17 +149,24 @@ class Environment < ActiveRecord::Base
slugified
=
name
.
to_s
.
downcase
.
gsub
(
/[^a-z0-9]/
,
'-'
)
slugified
=
name
.
to_s
.
downcase
.
gsub
(
/[^a-z0-9]/
,
'-'
)
# Must start with a letter
# 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)
# Maximum length: 24 characters (OpenShift limitation)
slugified
=
slugified
[
0
..
23
]
slugified
=
slugified
[
0
..
23
]
# Cannot end with a
"-" character
(Kubernetes label limitation)
# Cannot end with a
dash
(Kubernetes label limitation)
slugified
=
slugified
[
0
..-
2
]
if
slugified
[
-
1
]
==
"-"
slugified
.
chop!
if
slugified
.
end_with?
(
'-'
)
# Add a random suffix, shortening the current string if necessary, if it
# Add a random suffix, shortening the current string if necessary, if it
# has been slugified. This ensures uniqueness.
# 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
self
.
slug
=
slugified
end
end
...
...
changelogs/unreleased/26852-fix-slug-for-openshift.yml
0 → 100644
View file @
e806bdaf
---
title
:
Avoid repeated dashes in $CI_ENVIRONMENT_SLUG
merge_request
:
8638
author
:
db/migrate/20161207231626_add_environment_slug.rb
View file @
e806bdaf
...
@@ -8,8 +8,9 @@ class AddEnvironmentSlug < ActiveRecord::Migration
...
@@ -8,8 +8,9 @@ class AddEnvironmentSlug < ActiveRecord::Migration
DOWNTIME_REASON
=
'Adding NOT NULL column environments.slug with dependent data'
DOWNTIME_REASON
=
'Adding NOT NULL column environments.slug with dependent data'
# Used to generate random suffixes for the slug
# Used to generate random suffixes for the slug
LETTERS
=
'a'
..
'z'
NUMBERS
=
'0'
..
'9'
NUMBERS
=
'0'
..
'9'
SUFFIX_CHARS
=
(
'a'
..
'z'
)
.
to_a
+
NUMBERS
.
to_a
SUFFIX_CHARS
=
LETTERS
.
to_a
+
NUMBERS
.
to_a
def
up
def
up
environments
=
Arel
::
Table
.
new
(
:environments
)
environments
=
Arel
::
Table
.
new
(
:environments
)
...
@@ -39,17 +40,24 @@ class AddEnvironmentSlug < ActiveRecord::Migration
...
@@ -39,17 +40,24 @@ class AddEnvironmentSlug < ActiveRecord::Migration
slugified
=
name
.
to_s
.
downcase
.
gsub
(
/[^a-z0-9]/
,
'-'
)
slugified
=
name
.
to_s
.
downcase
.
gsub
(
/[^a-z0-9]/
,
'-'
)
# Must start with a letter
# 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)
# Maximum length: 24 characters (OpenShift limitation)
slugified
=
slugified
[
0
..
23
]
slugified
=
slugified
[
0
..
23
]
# Cannot end with a
"-" character
(Kubernetes label limitation)
# Cannot end with a
dash
(Kubernetes label limitation)
slugified
=
slugified
[
0
..-
2
]
if
slugified
[
-
1
]
==
"-"
slugified
.
chop!
if
slugified
.
end_with?
(
'-'
)
# Add a random suffix, shortening the current string if necessary, if it
# Add a random suffix, shortening the current string if necessary, if it
# has been slugified. This ensures uniqueness.
# 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
slugified
slugified
end
end
...
...
spec/models/environment_spec.rb
View file @
e806bdaf
...
@@ -288,6 +288,11 @@ describe Environment, models: true do
...
@@ -288,6 +288,11 @@ describe Environment, models: true do
"1-foo"
=>
"env-1-foo"
+
SUFFIX
,
"1-foo"
=>
"env-1-foo"
+
SUFFIX
,
"1/foo"
=>
"env-1-foo"
+
SUFFIX
,
"1/foo"
=>
"env-1-foo"
+
SUFFIX
,
"foo-"
=>
"foo"
+
SUFFIX
,
"foo-"
=>
"foo"
+
SUFFIX
,
"foo--bar"
=>
"foo-bar"
+
SUFFIX
,
"foo**bar"
=>
"foo-bar"
+
SUFFIX
,
"*-foo"
=>
"env-foo"
+
SUFFIX
,
"staging-12345678-"
=>
"staging-12345678"
+
SUFFIX
,
"staging-12345678-01234567"
=>
"staging-12345678"
+
SUFFIX
,
}.
each
do
|
name
,
matcher
|
}.
each
do
|
name
,
matcher
|
it
"returns a slug matching
#{
matcher
}
, given
#{
name
}
"
do
it
"returns a slug matching
#{
matcher
}
, given
#{
name
}
"
do
slug
=
described_class
.
new
(
name:
name
).
generate_slug
slug
=
described_class
.
new
(
name:
name
).
generate_slug
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment