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)
|
2015-04-26 12:48:37 +05:30
|
|
|
return error('You dont have push access to repo', 405)
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
unless branch
|
|
|
|
return error('No such branch', 404)
|
|
|
|
end
|
|
|
|
|
2015-12-23 02:04:40 +05:30
|
|
|
if repository.rm_branch(current_user, branch_name)
|
2014-09-02 18:07:02 +05:30
|
|
|
success('Branch was removed')
|
|
|
|
else
|
2015-04-26 12:48:37 +05:30
|
|
|
error('Failed to remove branch')
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
2016-08-24 12:49:21 +05:30
|
|
|
rescue GitHooksService::PreReceiveError => ex
|
|
|
|
error(ex.message)
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
def error(message, return_code = 400)
|
2016-08-24 12:49:21 +05:30
|
|
|
super(message).merge(return_code: return_code)
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def success(message)
|
2016-08-24 12:49:21 +05:30
|
|
|
super().merge(message: message)
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def build_push_data(branch)
|
2016-09-13 17:45:13 +05:30
|
|
|
Gitlab::DataBuilder::Push.build(
|
|
|
|
project,
|
|
|
|
current_user,
|
2016-11-24 13:41:30 +05:30
|
|
|
branch.dereferenced_target.sha,
|
2016-09-13 17:45:13 +05:30
|
|
|
Gitlab::Git::BLANK_SHA,
|
|
|
|
"#{Gitlab::Git::BRANCH_REF_PREFIX}#{branch.name}",
|
|
|
|
[])
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
end
|