debian-mirror-gitlab/app/services/ci/deployments/destroy_service.rb

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

19 lines
609 B
Ruby
Raw Normal View History

2022-08-27 11:52:29 +05:30
# frozen_string_literal: true
module Ci
module Deployments
class DestroyService < BaseService
def execute(deployment)
raise Gitlab::Access::AccessDeniedError unless can?(current_user, :destroy_deployment, deployment)
return ServiceResponse.error(message: 'Cannot destroy running deployment') if deployment&.running?
return ServiceResponse.error(message: 'Deployment currently deployed to environment') if deployment&.last?
project.destroy_deployment_by_id(deployment)
ServiceResponse.success(message: 'Deployment destroyed')
end
end
end
end