Commit ec0daedb authored by Grzegorz Bizon's avatar Grzegorz Bizon

Add service that runs after branch removed hooks

parent be3d74e0
require_relative 'base_service'
##
# Branch can be deleted either by DeleteBranchService
# or by GitPushService.
#
class AfterBranchDeleteService < BaseService
attr_reader :branch_name
def execute(branch_name)
@branch_name = branch_name
stop_environments
end
private
def stop_environments
Ci::StopEnvironmentService
.new(project, current_user)
.execute(branch_name)
end
end
...@@ -22,6 +22,7 @@ class DeleteBranchService < BaseService ...@@ -22,6 +22,7 @@ class DeleteBranchService < BaseService
end end
if repository.rm_branch(current_user, branch_name) if repository.rm_branch(current_user, branch_name)
execute_after_branch_delete_hooks(branch_name)
success('Branch was removed') success('Branch was removed')
else else
error('Failed to remove branch') error('Failed to remove branch')
...@@ -47,4 +48,12 @@ class DeleteBranchService < BaseService ...@@ -47,4 +48,12 @@ class DeleteBranchService < BaseService
"#{Gitlab::Git::BRANCH_REF_PREFIX}#{branch.name}", "#{Gitlab::Git::BRANCH_REF_PREFIX}#{branch.name}",
[]) [])
end end
private
def execute_after_branch_delete_hooks(branch_name)
AfterBranchDeleteService
.new(project, current_user)
.execute(branch_name)
end
end end
...@@ -49,10 +49,7 @@ class GitPushService < BaseService ...@@ -49,10 +49,7 @@ class GitPushService < BaseService
update_gitattributes if is_default_branch? update_gitattributes if is_default_branch?
end end
# Update merge requests that may be affected by this push. A new branch execute_related_hooks
# could cause the last commit of a merge request to change.
update_merge_requests
perform_housekeeping perform_housekeeping
end end
...@@ -62,14 +59,24 @@ class GitPushService < BaseService ...@@ -62,14 +59,24 @@ class GitPushService < BaseService
protected protected
def update_merge_requests def execute_related_hooks
UpdateMergeRequestsWorker.perform_async(@project.id, current_user.id, params[:oldrev], params[:newrev], params[:ref]) # Update merge requests that may be affected by this push. A new branch
# could cause the last commit of a merge request to change.
#
UpdateMergeRequestsWorker
.perform_async(@project.id, current_user.id, params[:oldrev], params[:newrev], params[:ref])
EventCreateService.new.push(@project, current_user, build_push_data) EventCreateService.new.push(@project, current_user, build_push_data)
@project.execute_hooks(build_push_data.dup, :push_hooks) @project.execute_hooks(build_push_data.dup, :push_hooks)
@project.execute_services(build_push_data.dup, :push_hooks) @project.execute_services(build_push_data.dup, :push_hooks)
Ci::CreatePipelineService.new(@project, current_user, build_push_data).execute Ci::CreatePipelineService.new(@project, current_user, build_push_data).execute
ProjectCacheWorker.perform_async(@project.id) ProjectCacheWorker.perform_async(@project.id)
if push_remove_branch?
AfterBranchDeleteService
.new(project, current_user)
.execute(branch_name)
end
end end
def perform_housekeeping def perform_housekeeping
......
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