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