1afab9eb79
It adds a button to the branches page that the user can use to delete all the branches that are already merged. This can be used to clean up all the branches that were forgotten to delete while merging MRs. Fixes #21076.
18 lines
544 B
Ruby
18 lines
544 B
Ruby
require_relative 'base_service'
|
|
|
|
class DeleteMergedBranchesService < BaseService
|
|
def async_execute
|
|
DeleteMergedBranchesWorker.perform_async(project.id, current_user.id)
|
|
end
|
|
|
|
def execute
|
|
raise Gitlab::Access::AccessDeniedError unless can?(current_user, :push_code, project)
|
|
|
|
branches = project.repository.branch_names
|
|
branches = branches.select { |branch| project.repository.merged_to_root_ref?(branch) }
|
|
|
|
branches.each do |branch|
|
|
DeleteBranchService.new(project, current_user).execute(branch)
|
|
end
|
|
end
|
|
end
|