Replace invalid chars while seeding environments

This commit is contained in:
Zeger-Jan van de Weg 2017-06-21 11:16:38 +00:00 committed by Grzegorz Bizon
parent 6a3da45a22
commit 5eb940da76
3 changed files with 14 additions and 2 deletions

View File

@ -33,7 +33,7 @@ class Gitlab::Seeder::Environments
create_deployment!(
merge_request.source_project,
"review/#{merge_request.source_branch}",
"review/#{merge_request.source_branch.gsub(/[^a-zA-Z0-9]/, '')}",
merge_request.source_branch,
merge_request.diff_head_sha
)

View File

@ -43,7 +43,7 @@ module Gitlab
end
def environment_name_regex_message
"can contain only letters, digits, '-', '_', '/', '$', '{', '}', '.' and spaces"
"can contain only letters, digits, '-', '_', '/', '$', '{', '}', '.', and spaces"
end
def kubernetes_namespace_regex

View File

@ -20,6 +20,18 @@ describe Gitlab::Regex, lib: true do
it { is_expected.to match('foo@bar') }
end
describe '.environment_slug_regex' do
subject { described_class.environment_name_regex }
it { is_expected.to match('foo') }
it { is_expected.to match('foo-1') }
it { is_expected.to match('FOO') }
it { is_expected.to match('foo/1') }
it { is_expected.to match('foo.1') }
it { is_expected.not_to match('9&foo') }
it { is_expected.not_to match('foo-^') }
end
describe '.environment_slug_regex' do
subject { described_class.environment_slug_regex }