Read about our upcoming Code of Conduct on this issue

This instance will be upgraded to Heptapod 0.28.1 on 2022-01-26 at 16:00 UTC+1 (a few minutes of down time)

Commit b3284b15 authored by Tiago Botelho's avatar Tiago Botelho
Browse files

Makes production environment the default environment for a project

parent 18b2e2a2b631
......@@ -121,7 +121,7 @@ def terminal_websocket_authorize
end
def metrics_redirect
environment = project.environments.with_state(:available).first
environment = project.default_environment
if environment
redirect_to environment_metrics_path(environment)
......
......@@ -1774,6 +1774,15 @@ def container_registry_variables
end
end
def default_environment
production_first = "(CASE WHEN name = 'production' THEN 0 ELSE 1 END), id ASC"
environments
.with_state(:available)
.reorder(production_first)
.first
end
def secret_variables_for(ref:, environment: nil)
# EE would use the environment
if protected_for?(ref)
......
......@@ -2292,6 +2292,28 @@ def create_build(new_pipeline = pipeline, name = 'test')
end
end
describe '#default_environment' do
let(:project) { create(:project) }
it 'returns production environment when it exists' do
production = create(:environment, name: "production", project: project)
create(:environment, name: 'staging', project: project)
expect(project.default_environment).to eq(production)
end
it 'returns first environment when no production environment exists' do
create(:environment, name: 'staging', project: project)
create(:environment, name: 'foo', project: project)
expect(project.default_environment).to eq(project.environments.first)
end
it 'returns nil when no available environment exists' do
expect(project.default_environment).to be_nil
end
end
describe '#secret_variables_for' do
let(:project) { create(:project) }
......
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