Welcome to mirror list, hosted at ThFree Co, Russian Federation.

delete_branch_service.rb « services « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 4c3ac19f754f597ea0a0f8e06b159d580f9fc3f5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# frozen_string_literal: true

class DeleteBranchService < BaseService
  def execute(branch_name)
    repository = project.repository
    branch = repository.find_branch(branch_name)

    unless current_user.can?(:push_code, project)
      return error('You dont have push access to repo', 405)
    end

    unless branch
      return error('No such branch', 404)
    end

    if repository.rm_branch(current_user, branch_name)
      success('Branch was deleted')
    else
      error('Failed to remove branch')
    end
  rescue Gitlab::Git::PreReceiveError => ex
    error(ex.message)
  end

  def error(message, return_code = 400)
    super(message).merge(return_code: return_code)
  end

  def success(message)
    super().merge(message: message)
  end
end