Class: Branches::DeleteService
- Inherits:
-
BaseService
- Object
- BaseService
- Branches::DeleteService
- Defined in:
- app/services/branches/delete_service.rb
Constant Summary
Constants inherited from BaseService
BaseService::UnauthorizedError
Instance Attribute Summary
Attributes inherited from BaseService
#current_user, #params, #project
Instance Method Summary collapse
Methods inherited from BaseService
Methods included from BaseServiceUtility
#deny_visibility_level, #event_service, #log_error, #log_info, #notification_service, #system_hook_service, #todo_service, #visibility_level
Methods included from Gitlab::Allowable
Constructor Details
This class inherits a constructor from BaseService
Instance Method Details
#execute(branch_name) ⇒ Object
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 33 |
# File 'app/services/branches/delete_service.rb', line 5 def execute(branch_name) repository = project.repository unless current_user.can?(:push_code, project) return ServiceResponse.error( message: 'You dont have push access to repo', http_status: 405) end return missing_branch_error if branch_name.blank? branch = repository.find_branch(branch_name) return missing_branch_error unless branch target_sha = branch.dereferenced_target.id if repository.rm_branch(current_user, branch_name, target_sha: target_sha) unlock_artifacts(branch_name) ServiceResponse.success(message: 'Branch was deleted') else ServiceResponse.error( payload: { branch: branch }, message: 'Failed to remove branch', http_status: 400) end rescue Gitlab::Git::PreReceiveError, Gitlab::Git::CommandError => ex ServiceResponse.error(payload: { branch: branch }, message: ex., http_status: 400) end |