Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
gitlab-ce
Commits
99dea5fa
Commit
99dea5fa
authored
Jul 03, 2018
by
Tiago Botelho
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Makes production environment the default environment for a project
parent
55e2df6c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
32 additions
and
1 deletion
+32
-1
app/controllers/projects/environments_controller.rb
app/controllers/projects/environments_controller.rb
+1
-1
app/models/project.rb
app/models/project.rb
+9
-0
spec/models/project_spec.rb
spec/models/project_spec.rb
+22
-0
No files found.
app/controllers/projects/environments_controller.rb
View file @
99dea5fa
...
...
@@ -121,7 +121,7 @@ class Projects::EnvironmentsController < Projects::ApplicationController
end
def
metrics_redirect
environment
=
project
.
environments
.
with_state
(
:available
).
firs
t
environment
=
project
.
default_environmen
t
if
environment
redirect_to
environment_metrics_path
(
environment
)
...
...
app/models/project.rb
View file @
99dea5fa
...
...
@@ -1774,6 +1774,15 @@ class Project < ActiveRecord::Base
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
)
...
...
spec/models/project_spec.rb
View file @
99dea5fa
...
...
@@ -2292,6 +2292,28 @@ describe Project do
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
)
}
...
...
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