debian-mirror-gitlab/app/services/projects/auto_devops/disable_service.rb

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

42 lines
1.2 KiB
Ruby
Raw Normal View History

2018-11-20 20:47:30 +05:30
# frozen_string_literal: true
module Projects
module AutoDevops
class DisableService < BaseService
def execute
return false unless implicitly_enabled_and_first_pipeline_failure?
disable_auto_devops
end
private
def implicitly_enabled_and_first_pipeline_failure?
project.has_auto_devops_implicitly_enabled? &&
first_pipeline_failure?
end
# We're using `limit` to optimize `auto_devops pipeline` query,
# since we only care about the first element, and using only `.count`
# is an expensive operation. See
2019-12-04 20:38:33 +05:30
# https://gitlab.com/gitlab-org/gitlab-foss/merge_requests/21172#note_99037378
2018-11-20 20:47:30 +05:30
# for more context.
2018-12-05 23:21:45 +05:30
# rubocop: disable CodeReuse/ActiveRecord
2018-11-20 20:47:30 +05:30
def first_pipeline_failure?
2020-10-24 23:57:45 +05:30
auto_devops_pipelines.success.limit(1).count == 0 &&
2018-11-20 20:47:30 +05:30
auto_devops_pipelines.failed.limit(1).count.nonzero?
end
2018-12-05 23:21:45 +05:30
# rubocop: enable CodeReuse/ActiveRecord
2018-11-20 20:47:30 +05:30
def disable_auto_devops
project.auto_devops_attributes = { enabled: false }
project.save!
end
def auto_devops_pipelines
2019-02-15 15:39:39 +05:30
@auto_devops_pipelines ||= project.ci_pipelines.auto_devops_source
2018-11-20 20:47:30 +05:30
end
end
end
end