Commit e6487168 authored by Matija Čupić's avatar Matija Čupić

Read the AutoDevOps instance domain in ProjectAutoDevOps

parent a3153984
......@@ -1609,13 +1609,7 @@ class Project < ActiveRecord::Base
def auto_devops_variables
return [] unless auto_devops_enabled?
auto_devops&.variables || if current_application_settings.auto_devops_domain.present?
[{ key: 'AUTO_DEVOPS_DOMAIN',
value: current_application_settings.auto_devops_domain,
public: true }]
else
[]
end
(auto_devops || ProjectAutoDevops.new)&.variables
end
def append_or_update_attribute(name, value)
......
class ProjectAutoDevops < ActiveRecord::Base
include Gitlab::CurrentSettings
belongs_to :project
scope :enabled, -> { where(enabled: true) }
......@@ -6,13 +8,17 @@ class ProjectAutoDevops < ActiveRecord::Base
validates :domain, allow_blank: true, hostname: { allow_numeric_hostname: true }
def instance_domain
current_application_settings.auto_devops_domain
end
def has_domain?
domain.present?
domain.present? || instance_domain.present?
end
def variables
variables = []
variables << { key: 'AUTO_DEVOPS_DOMAIN', value: domain, public: true } if domain.present?
variables << { key: 'AUTO_DEVOPS_DOMAIN', value: domain || instance_domain, public: true } if has_domain?
variables
end
end
......@@ -18,7 +18,21 @@ describe ProjectAutoDevops do
context 'when domain is empty' do
let(:auto_devops) { build_stubbed(:project_auto_devops, project: project, domain: '') }
it { expect(auto_devops).not_to have_domain }
context 'when there is an instance domain specified' do
before do
stub_application_setting(auto_devops_domain: 'example.com')
end
it { expect(auto_devops).to have_domain }
end
context 'when there is no instance domain specified' do
before do
stub_application_setting(auto_devops_domain: nil)
end
it { expect(auto_devops).not_to have_domain }
end
end
end
......@@ -29,9 +43,32 @@ describe ProjectAutoDevops do
let(:domain) { 'example.com' }
it 'returns AUTO_DEVOPS_DOMAIN' do
expect(auto_devops.variables).to include(
{ key: 'AUTO_DEVOPS_DOMAIN', value: 'example.com', public: true })
expect(auto_devops.variables).to include(domain_variable)
end
end
context 'when domain is not defined' do
let(:domain) { nil }
context 'when there is an instance domain specified' do
before do
stub_application_setting(auto_devops_domain: 'example.com')
end
it { expect(auto_devops.variables).to include(domain_variable) }
end
context 'when there is no instance domain specified' do
before do
stub_application_setting(auto_devops_domain: nil)
end
it { expect(auto_devops.variables).not_to include(domain_variable) }
end
end
def domain_variable
{ key: 'AUTO_DEVOPS_DOMAIN', value: 'example.com', public: true }
end
end
end
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