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
4a7fcc2a
Commit
4a7fcc2a
authored
Nov 09, 2016
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Stop environments for branch after branch removal
parent
5328e3b1
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
29 additions
and
9 deletions
+29
-9
app/models/project.rb
app/models/project.rb
+2
-2
app/models/repository.rb
app/models/repository.rb
+13
-2
app/services/delete_branch_service.rb
app/services/delete_branch_service.rb
+0
-2
app/services/git_push_service.rb
app/services/git_push_service.rb
+1
-1
lib/gitlab/github_import/importer.rb
lib/gitlab/github_import/importer.rb
+1
-1
spec/models/repository_spec.rb
spec/models/repository_spec.rb
+12
-1
No files found.
app/models/project.rb
View file @
4a7fcc2a
...
@@ -1289,12 +1289,12 @@ class Project < ActiveRecord::Base
...
@@ -1289,12 +1289,12 @@ class Project < ActiveRecord::Base
end
end
def
environments_for
(
ref
,
commit:
nil
,
with_tags:
false
)
def
environments_for
(
ref
,
commit:
nil
,
with_tags:
false
)
environments_query
=
with_tags
?
'ref
=? OR tag IS TRUE'
:
'ref=
?'
environments_query
=
with_tags
?
'ref
= ? OR tag IS TRUE'
:
'ref =
?'
environment_ids
=
deployments
environment_ids
=
deployments
.
group
(
:environment_id
)
.
group
(
:environment_id
)
.
select
(
:environment_id
)
.
select
(
:environment_id
)
.
where
(
environments_query
,
ref
)
.
where
(
environments_query
,
ref
.
to_s
)
envs
=
environments
.
available
.
where
(
id:
environment_ids
)
envs
=
environments
.
available
.
where
(
id:
environment_ids
)
...
...
app/models/repository.rb
View file @
4a7fcc2a
...
@@ -203,7 +203,7 @@ class Repository
...
@@ -203,7 +203,7 @@ class Repository
update_ref!
(
ref
,
newrev
,
oldrev
)
update_ref!
(
ref
,
newrev
,
oldrev
)
end
end
after_remove_branch
after_remove_branch
(
user
,
branch_name
)
true
true
end
end
...
@@ -524,7 +524,12 @@ class Repository
...
@@ -524,7 +524,12 @@ class Repository
end
end
# Runs code after an existing branch has been removed.
# Runs code after an existing branch has been removed.
def
after_remove_branch
def
after_remove_branch
(
user
,
branch_name
)
expire_branch_cache_after_removal
stop_environments_for_branch
(
user
,
branch_name
)
end
def
expire_branch_cache_after_removal
expire_has_visible_content_cache
expire_has_visible_content_cache
expire_branch_count_cache
expire_branch_count_cache
expire_branches_cache
expire_branches_cache
...
@@ -1165,4 +1170,10 @@ class Repository
...
@@ -1165,4 +1170,10 @@ class Repository
def
repository_event
(
event
,
tags
=
{})
def
repository_event
(
event
,
tags
=
{})
Gitlab
::
Metrics
.
add_event
(
event
,
{
path:
path_with_namespace
}.
merge
(
tags
))
Gitlab
::
Metrics
.
add_event
(
event
,
{
path:
path_with_namespace
}.
merge
(
tags
))
end
end
def
stop_environments_for_branch
(
user
,
branch_name
)
Ci
::
StopEnvironmentService
.
new
(
@project
,
user
)
.
execute
(
branch_name
)
end
end
end
app/services/delete_branch_service.rb
View file @
4a7fcc2a
...
@@ -21,8 +21,6 @@ class DeleteBranchService < BaseService
...
@@ -21,8 +21,6 @@ class DeleteBranchService < BaseService
return
error
(
'You dont have push access to repo'
,
405
)
return
error
(
'You dont have push access to repo'
,
405
)
end
end
# StopEnvironmentService
if
repository
.
rm_branch
(
current_user
,
branch_name
)
if
repository
.
rm_branch
(
current_user
,
branch_name
)
success
(
'Branch was removed'
)
success
(
'Branch was removed'
)
else
else
...
...
app/services/git_push_service.rb
View file @
4a7fcc2a
...
@@ -21,7 +21,7 @@ class GitPushService < BaseService
...
@@ -21,7 +21,7 @@ class GitPushService < BaseService
@project
.
repository
.
after_push_commit
(
branch_name
,
params
[
:newrev
])
@project
.
repository
.
after_push_commit
(
branch_name
,
params
[
:newrev
])
if
push_remove_branch?
if
push_remove_branch?
@project
.
repository
.
after_remove_branch
@project
.
repository
.
after_remove_branch
(
current_user
,
branch_name
)
@push_commits
=
[]
@push_commits
=
[]
elsif
push_to_new_branch?
elsif
push_to_new_branch?
@project
.
repository
.
after_create_branch
@project
.
repository
.
after_create_branch
...
...
lib/gitlab/github_import/importer.rb
View file @
4a7fcc2a
...
@@ -111,7 +111,7 @@ module Gitlab
...
@@ -111,7 +111,7 @@ module Gitlab
end
end
end
end
project
.
repository
.
after_remove_branch
project
.
repository
.
expire_branch_cache_after_removal
end
end
def
restore_source_branch
(
pull_request
)
def
restore_source_branch
(
pull_request
)
...
...
spec/models/repository_spec.rb
View file @
4a7fcc2a
...
@@ -1182,7 +1182,18 @@ describe Repository, models: true do
...
@@ -1182,7 +1182,18 @@ describe Repository, models: true do
it
'flushes the visible content cache'
do
it
'flushes the visible content cache'
do
expect
(
repository
).
to
receive
(
:expire_has_visible_content_cache
)
expect
(
repository
).
to
receive
(
:expire_has_visible_content_cache
)
repository
.
after_remove_branch
repository
.
after_remove_branch
(
user
,
'master'
)
end
context
'when there is environment with review app available for branch'
do
before
do
create
(
:environment
,
:with_review_app
,
project:
project
)
end
it
'stops environment'
do
expect_any_instance_of
(
Environment
).
to
receive
(
:stop!
)
repository
.
after_remove_branch
(
user
,
'master'
)
end
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