2018-12-05 23:21:45 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Ci
|
|
|
|
class ProcessBuildService < BaseService
|
|
|
|
def execute(build, current_status)
|
2020-03-13 15:44:24 +05:30
|
|
|
if valid_statuses_for_build(build).include?(current_status)
|
2018-12-05 23:21:45 +05:30
|
|
|
if build.schedulable?
|
|
|
|
build.schedule
|
|
|
|
elsif build.action?
|
|
|
|
build.actionize
|
|
|
|
else
|
|
|
|
enqueue(build)
|
|
|
|
end
|
|
|
|
|
|
|
|
true
|
|
|
|
else
|
|
|
|
build.skip
|
|
|
|
false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def enqueue(build)
|
|
|
|
build.enqueue
|
|
|
|
end
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
def valid_statuses_for_build(build)
|
|
|
|
case build.when
|
2018-12-05 23:21:45 +05:30
|
|
|
when 'on_success'
|
2020-03-13 15:44:24 +05:30
|
|
|
build.scheduling_type_dag? ? %w[success] : %w[success skipped]
|
2018-12-05 23:21:45 +05:30
|
|
|
when 'on_failure'
|
|
|
|
%w[failed]
|
|
|
|
when 'always'
|
|
|
|
%w[success failed skipped]
|
|
|
|
when 'manual'
|
|
|
|
%w[success skipped]
|
|
|
|
when 'delayed'
|
|
|
|
%w[success skipped]
|
|
|
|
else
|
|
|
|
[]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-12-04 20:38:33 +05:30
|
|
|
|
|
|
|
Ci::ProcessBuildService.prepend_if_ee('EE::Ci::ProcessBuildService')
|