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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
04a8372c
Commit
04a8372c
authored
Nov 08, 2016
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add environment teardown service
parent
e671cd89
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
68 additions
and
0 deletions
+68
-0
app/services/ci/stop_environment_service.rb
app/services/ci/stop_environment_service.rb
+31
-0
app/services/delete_branch_service.rb
app/services/delete_branch_service.rb
+2
-0
spec/services/ci/stop_environment_service_spec.rb
spec/services/ci/stop_environment_service_spec.rb
+35
-0
No files found.
app/services/ci/stop_environment_service.rb
0 → 100644
View file @
04a8372c
module
Ci
class
StopEnvironmentService
<
BaseService
def
execute
(
ref
)
@ref
=
ref
@commit
=
project
.
commit
(
ref
)
return
unless
has_ref_sha_pair?
return
unless
has_environments?
environments
.
each
do
|
environment
|
next
unless
environment
.
stoppable?
environment
.
stop!
(
current_user
)
end
end
private
def
has_ref_sha_pair?
@ref
&&
@commit
end
def
has_environments?
environments
.
any?
end
def
environments
@environments
||=
project
.
environments_for
(
@ref
,
@commit
)
end
end
end
app/services/delete_branch_service.rb
View file @
04a8372c
...
...
@@ -21,6 +21,8 @@ class DeleteBranchService < BaseService
return
error
(
'You dont have push access to repo'
,
405
)
end
# StopEnvironmentService
if
repository
.
rm_branch
(
current_user
,
branch_name
)
success
(
'Branch was removed'
)
else
...
...
spec/services/ci/stop_environment_service_spec.rb
0 → 100644
View file @
04a8372c
require
'spec_helper'
describe
Ci
::
StopEnvironmentService
,
services:
true
do
let
(
:project
)
{
create
(
:project
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:service
)
{
described_class
.
new
(
project
,
user
)
}
describe
'#execute'
do
context
'when environment exists'
do
let
(
:environment
)
{
create
(
:environment
,
project:
project
)
}
let
(
:deployable
)
{
create
(
:ci_build
)
}
let
(
:stop_build
)
do
create
(
:ci_build
,
:manual
,
name:
'environment/teardown'
,
pipeline:
deployable
.
pipeline
)
end
before
do
create
(
:deployment
,
environment:
environment
,
deployable:
deployable
,
on_stop:
stop_build
.
name
,
user:
user
,
project:
project
,
sha:
project
.
commit
.
id
)
end
it
'stops environment'
do
expect_any_instance_of
(
Environment
).
to
receive
(
:stop!
)
service
.
execute
(
'master'
)
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