2018-09-25 05:21:41 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Ci
|
2018-09-25 05:24:08 +00:00
|
|
|
class ProcessBuildService < BaseService
|
2018-09-27 07:10:55 +00:00
|
|
|
def execute(build, current_status)
|
|
|
|
if valid_statuses_for_when(build.when).include?(current_status)
|
|
|
|
if build.schedulable?
|
2018-09-28 06:55:13 +00:00
|
|
|
build.schedule
|
2018-09-27 07:10:55 +00:00
|
|
|
elsif build.action?
|
|
|
|
build.actionize
|
|
|
|
else
|
2018-10-02 09:35:34 +00:00
|
|
|
enqueue(build)
|
2018-09-27 07:10:55 +00:00
|
|
|
end
|
2018-09-28 05:41:39 +00:00
|
|
|
|
2018-09-27 07:10:55 +00:00
|
|
|
true
|
2018-09-25 05:21:41 +00:00
|
|
|
else
|
2018-09-27 07:10:55 +00:00
|
|
|
build.skip
|
|
|
|
false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2018-10-02 09:35:34 +00:00
|
|
|
def enqueue(build)
|
|
|
|
build.enqueue
|
|
|
|
end
|
|
|
|
|
2018-09-27 07:10:55 +00:00
|
|
|
def valid_statuses_for_when(value)
|
|
|
|
case value
|
|
|
|
when 'on_success'
|
|
|
|
%w[success skipped]
|
|
|
|
when 'on_failure'
|
|
|
|
%w[failed]
|
|
|
|
when 'always'
|
|
|
|
%w[success failed skipped]
|
|
|
|
when 'manual'
|
|
|
|
%w[success skipped]
|
|
|
|
when 'delayed'
|
|
|
|
%w[success skipped]
|
|
|
|
else
|
|
|
|
[]
|
2018-09-25 05:21:41 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|