2018-11-18 11:00:15 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
class DeleteBranchService < BaseService
|
|
|
|
def execute(branch_name)
|
2014-09-02 18:07:02 +05:30
|
|
|
repository = project.repository
|
|
|
|
branch = repository.find_branch(branch_name)
|
|
|
|
|
|
|
|
unless current_user.can?(:push_code, project)
|
2019-07-31 22:56:46 +05:30
|
|
|
return ServiceResponse.error(
|
|
|
|
message: 'You dont have push access to repo',
|
|
|
|
http_status: 405)
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
unless branch
|
2019-07-31 22:56:46 +05:30
|
|
|
return ServiceResponse.error(
|
|
|
|
message: 'No such branch',
|
|
|
|
http_status: 404)
|
2017-09-10 17:25:29 +05:30
|
|
|
end
|
|
|
|
|
2015-12-23 02:04:40 +05:30
|
|
|
if repository.rm_branch(current_user, branch_name)
|
2019-07-31 22:56:46 +05:30
|
|
|
ServiceResponse.success(message: 'Branch was deleted')
|
2014-09-02 18:07:02 +05:30
|
|
|
else
|
2019-07-31 22:56:46 +05:30
|
|
|
ServiceResponse.error(
|
|
|
|
message: 'Failed to remove branch',
|
|
|
|
http_status: 400)
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
2018-11-08 19:23:39 +05:30
|
|
|
rescue Gitlab::Git::PreReceiveError => ex
|
2019-07-31 22:56:46 +05:30
|
|
|
ServiceResponse.error(message: ex.message, http_status: 400)
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
end
|