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
Tatuya Kamada
gitlab-ce
Commits
3f85c3ef
Commit
3f85c3ef
authored
Oct 06, 2016
by
Kamil Trzcinski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Initial support for closing environments
parent
2c01b19f
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
58 additions
and
2 deletions
+58
-2
app/models/ci/build.rb
app/models/ci/build.rb
+4
-0
app/models/deployment.rb
app/models/deployment.rb
+13
-0
app/models/environment.rb
app/models/environment.rb
+18
-0
app/services/create_deployment_service.rb
app/services/create_deployment_service.rb
+11
-1
db/migrate/20161006104309_add_state_to_environment.rb
db/migrate/20161006104309_add_state_to_environment.rb
+9
-0
lib/gitlab/ci/config/node/environment.rb
lib/gitlab/ci/config/node/environment.rb
+3
-1
No files found.
app/models/ci/build.rb
View file @
3f85c3ef
...
@@ -110,6 +110,10 @@ module Ci
...
@@ -110,6 +110,10 @@ module Ci
project
.
builds_enabled?
&&
commands
.
present?
&&
manual?
&&
skipped?
project
.
builds_enabled?
&&
commands
.
present?
&&
manual?
&&
skipped?
end
end
def
closes_environment?
(
name
)
environment
==
name
&&
options
.
fetch
(
:environment
,
{}).
fetch
(
:close
,
false
)
end
def
play
(
current_user
=
nil
)
def
play
(
current_user
=
nil
)
# Try to queue a current build
# Try to queue a current build
if
self
.
enqueue
if
self
.
enqueue
...
...
app/models/deployment.rb
View file @
3f85c3ef
...
@@ -77,6 +77,19 @@ class Deployment < ActiveRecord::Base
...
@@ -77,6 +77,19 @@ class Deployment < ActiveRecord::Base
take
take
end
end
def
close_action
return
nil
unless
manual_actions
@close_action
||=
manual_actions
.
find
do
|
manual_action
|
manual_action
.
try
(
:closes_environment?
,
deployable
.
environment
)
end
end
def
closeable?
close_action
.
present?
end
private
private
def
ref_path
def
ref_path
...
...
app/models/environment.rb
View file @
3f85c3ef
...
@@ -19,6 +19,24 @@ class Environment < ActiveRecord::Base
...
@@ -19,6 +19,24 @@ class Environment < ActiveRecord::Base
allow_nil:
true
,
allow_nil:
true
,
addressable_url:
true
addressable_url:
true
delegate
:closeable?
,
:close_action
,
to: :last_deployment
,
allow_nil:
true
scope
:opened
,
->
{
where
(
state:
[
:opened
])
}
scope
:closed
,
->
{
where
(
state:
[
:closed
])
}
state_machine
:state
,
initial: :opened
do
event
:close
do
transition
opened: :closed
end
event
:reopen
do
transition
closed: :opened
end
state
:opened
state
:closed
end
def
last_deployment
def
last_deployment
deployments
.
last
deployments
.
last
end
end
...
...
app/services/create_deployment_service.rb
View file @
3f85c3ef
...
@@ -4,6 +4,13 @@ class CreateDeploymentService < BaseService
...
@@ -4,6 +4,13 @@ class CreateDeploymentService < BaseService
def
execute
(
deployable
=
nil
)
def
execute
(
deployable
=
nil
)
environment
=
find_or_create_environment
environment
=
find_or_create_environment
if
close?
environment
.
close
return
end
environment
.
reopen
deployment
=
project
.
deployments
.
create
(
deployment
=
project
.
deployments
.
create
(
environment:
environment
,
environment:
environment
,
ref:
params
[
:ref
],
ref:
params
[
:ref
],
...
@@ -14,7 +21,6 @@ class CreateDeploymentService < BaseService
...
@@ -14,7 +21,6 @@ class CreateDeploymentService < BaseService
)
)
deployment
.
update_merge_request_metrics!
deployment
.
update_merge_request_metrics!
deployment
deployment
end
end
...
@@ -44,6 +50,10 @@ class CreateDeploymentService < BaseService
...
@@ -44,6 +50,10 @@ class CreateDeploymentService < BaseService
options
[
:url
]
options
[
:url
]
end
end
def
close?
options
[
:close
]
end
def
options
def
options
params
[
:options
]
||
{}
params
[
:options
]
||
{}
end
end
...
...
db/migrate/20161006104309_add_state_to_environment.rb
0 → 100644
View file @
3f85c3ef
class
AddStateToEnvironment
<
ActiveRecord
::
Migration
include
Gitlab
::
Database
::
MigrationHelpers
DOWNTIME
=
false
def
change
add_column
:environments
,
:state
,
:string
end
end
lib/gitlab/ci/config/node/environment.rb
View file @
3f85c3ef
...
@@ -8,7 +8,7 @@ module Gitlab
...
@@ -8,7 +8,7 @@ module Gitlab
class
Environment
<
Entry
class
Environment
<
Entry
include
Validatable
include
Validatable
ALLOWED_KEYS
=
%i[name url]
ALLOWED_KEYS
=
%i[name url
close
]
validations
do
validations
do
validate
do
validate
do
...
@@ -35,6 +35,8 @@ module Gitlab
...
@@ -35,6 +35,8 @@ module Gitlab
length:
{
maximum:
255
},
length:
{
maximum:
255
},
addressable_url:
true
,
addressable_url:
true
,
allow_nil:
true
allow_nil:
true
validates
:close
,
boolean:
true
,
allow_nil:
true
end
end
end
end
...
...
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