Commit 87a9dfa8 authored by Alan Andrade's avatar Alan Andrade Committed by Alan Andrade

Use the environment tier for jira connect deployment environment type

Jira connect was guessing the deployment enrivonment type by testing
a regex on the environment name. This commit updates jira connect
to use the environment tier instead.

Changelog: changed
parent 56fe6f88
......@@ -461,11 +461,16 @@ class Environment < ApplicationRecord
# See https://en.wikipedia.org/wiki/Deployment_environment for industry standard deployment environments
def guess_tier
case name
when %r{dev|review|trunk}i then self.class.tiers[:development]
when %r{test|qc}i then self.class.tiers[:testing]
when %r{st(a|)g|mod(e|)l|pre|demo}i then self.class.tiers[:staging]
when %r{pr(o|)d|live}i then self.class.tiers[:production]
else self.class.tiers[:other]
when /(dev|review|trunk)/i
self.class.tiers[:development]
when /(test|tst|int|ac(ce|)pt|qa|qc|control|quality)/i
self.class.tiers[:testing]
when /(st(a|)g|mod(e|)l|pre|demo)/i
self.class.tiers[:staging]
when /(pr(o|)d|live)/i
self.class.tiers[:production]
else
self.class.tiers[:other]
end
end
end
......
......@@ -20,18 +20,7 @@ module Atlassian
end
def type
case environment.name
when /\A(.*[^a-z0-9])?(staging|stage|stg|preprod|pre-prod|model|internal)([^a-z0-9].*)?\z/i
'staging'
when /\A(.*[^a-z0-9])?(prod|production|prd|live)([^a-z0-9].*)?\z/i
'production'
when /\A(.*[^a-z0-9])?(test|testing|tests|tst|integration|integ|intg|int|acceptance|accept|acpt|qa|qc|control|quality)([^a-z0-9].*)?\z/i
'testing'
when /\A(.*[^a-z0-9])?(dev|review|development)([^a-z0-9].*)?\z/i
'development'
else
'unmapped'
end
environment.tier == 'other' ? 'unmapped' : environment.tier
end
end
end
......
......@@ -45,33 +45,18 @@ RSpec.describe Atlassian::JiraConnect::Serializers::DeploymentEntity do
describe 'environment type' do
using RSpec::Parameterized::TableSyntax
where(:env_name, :env_type) do
'PRODUCTION' | 'production'
'prod' | 'production'
'prod-east-2' | 'production'
'us-prod-east' | 'production'
'fe-production' | 'production'
'test' | 'testing'
'qa-env-2' | 'testing'
'staging' | 'staging'
'pre-prod' | 'staging'
'blue-kit-stage' | 'staging'
'pre-prod' | 'staging'
'dev' | 'development'
'review/app' | 'development'
'something-else' | 'unmapped'
'store-produce' | 'unmapped'
'unproductive' | 'unmapped'
where(:tier, :env_type) do
'other' | 'unmapped'
end
with_them do
before do
environment.update!(name: env_name)
subject.environment.update!(tier: tier)
end
let(:exposed_type) { subject.send(:environment_entity).send(:type) }
it 'has the correct environment type' do
it 'has the same type as the environment tier' do
expect(exposed_type).to eq(env_type)
end
end
......
......@@ -282,6 +282,13 @@ RSpec.describe Environment, :use_clean_rails_memory_store_caching do
'DEV' | described_class.tiers[:development]
'development' | described_class.tiers[:development]
'trunk' | described_class.tiers[:development]
'dev' | described_class.tiers[:development]
'review/app' | described_class.tiers[:development]
'PRODUCTION' | described_class.tiers[:production]
'prod' | described_class.tiers[:production]
'prod-east-2' | described_class.tiers[:production]
'us-prod-east' | described_class.tiers[:production]
'fe-production' | described_class.tiers[:production]
'test' | described_class.tiers[:testing]
'TEST' | described_class.tiers[:testing]
'testing' | described_class.tiers[:testing]
......@@ -290,6 +297,7 @@ RSpec.describe Environment, :use_clean_rails_memory_store_caching do
'production-test' | described_class.tiers[:testing]
'test-production' | described_class.tiers[:testing]
'QC' | described_class.tiers[:testing]
'qa-env-2' | described_class.tiers[:testing]
'gstg' | described_class.tiers[:staging]
'staging' | described_class.tiers[:staging]
'stage' | described_class.tiers[:staging]
......@@ -298,6 +306,10 @@ RSpec.describe Environment, :use_clean_rails_memory_store_caching do
'Pre-production' | described_class.tiers[:staging]
'pre' | described_class.tiers[:staging]
'Demo' | described_class.tiers[:staging]
'staging' | described_class.tiers[:staging]
'pre-prod' | described_class.tiers[:staging]
'blue-kit-stage' | described_class.tiers[:staging]
'pre-prod' | described_class.tiers[:staging]
'gprd' | described_class.tiers[:production]
'gprd-cny' | described_class.tiers[:production]
'production' | described_class.tiers[:production]
......@@ -307,6 +319,8 @@ RSpec.describe Environment, :use_clean_rails_memory_store_caching do
'production/eu' | described_class.tiers[:production]
'PRODUCTION/EU' | described_class.tiers[:production]
'productioneu' | described_class.tiers[:production]
'store-produce' | described_class.tiers[:production]
'unproductive' | described_class.tiers[:production]
'production/www.gitlab.com' | described_class.tiers[:production]
'prod' | described_class.tiers[:production]
'PROD' | described_class.tiers[:production]
......@@ -314,6 +328,7 @@ RSpec.describe Environment, :use_clean_rails_memory_store_caching do
'canary' | described_class.tiers[:other]
'other' | described_class.tiers[:other]
'EXP' | described_class.tiers[:other]
'something-else' | described_class.tiers[:other]
end
with_them do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment