debian-mirror-gitlab/app/services/branches/delete_service.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

40 lines
1.1 KiB
Ruby
Raw Normal View History

2020-01-01 13:55:28 +05:30
# frozen_string_literal: true
module Branches
class DeleteService < BaseService
def execute(branch_name)
repository = project.repository
branch = repository.find_branch(branch_name)
unless current_user.can?(:push_code, project)
return ServiceResponse.error(
message: 'You dont have push access to repo',
http_status: 405)
end
unless branch
return ServiceResponse.error(
message: 'No such branch',
http_status: 404)
end
if repository.rm_branch(current_user, branch_name)
2020-07-28 23:09:34 +05:30
unlock_artifacts(branch_name)
2020-01-01 13:55:28 +05:30
ServiceResponse.success(message: 'Branch was deleted')
else
ServiceResponse.error(
message: 'Failed to remove branch',
http_status: 400)
end
2020-11-24 15:15:51 +05:30
rescue Gitlab::Git::PreReceiveError, Gitlab::Git::CommandError => ex
2020-01-01 13:55:28 +05:30
ServiceResponse.error(message: ex.message, http_status: 400)
end
2020-07-28 23:09:34 +05:30
private
def unlock_artifacts(branch_name)
Ci::RefDeleteUnlockArtifactsWorker.perform_async(project.id, current_user.id, "#{::Gitlab::Git::BRANCH_REF_PREFIX}#{branch_name}")
end
2020-01-01 13:55:28 +05:30
end
end