Commit c03631a9 authored by Shinya Maeda's avatar Shinya Maeda Committed by Alessio Caiazza

Support new syntax

parent 3fc4c096
......@@ -186,6 +186,7 @@ module Ci
end
after_transition any => [:manual] do |build|
puts "#{self.class.name} - #{__callee__}: 1"
build.run_after_commit do
build.schedule_delayed_execution
end
......@@ -236,22 +237,22 @@ module Ci
action? && (manual? || retryable?)
end
def autoplay?
manual? && options[:autoplay_in].present?
def delayed?
manual? && options[:start_in].present?
end
def autoplay_at
ChronicDuration.parse(options[:autoplay_in])&.seconds&.from_now
def execute_at
ChronicDuration.parse(options[:start_in])&.seconds&.from_now
end
def schedule_delayed_execution
return unless autoplay?
return unless delayed?
create_build_schedule!(execute_at: autoplay_at)
create_build_schedule!(execute_at: execute_at)
end
def action?
self.when == 'manual'
self.when == 'manual' || self.when == 'delayed'
end
# rubocop: disable CodeReuse/ServiceClass
......
......@@ -53,7 +53,7 @@ module Ci
%w[failed]
when 'always'
%w[success failed skipped]
when 'manual'
when 'manual', 'delayed'
%w[success skipped]
else
[]
......
......@@ -10,7 +10,7 @@ module Gitlab
include Attributable
ALLOWED_KEYS = %i[tags script only except type image services
allow_failure type stage when autoplay_in artifacts cache
allow_failure type stage when start_in artifacts cache
dependencies before_script after_script variables
environment coverage retry extends].freeze
......@@ -28,7 +28,7 @@ module Gitlab
greater_than_or_equal_to: 0,
less_than_or_equal_to: 2 }
validates :when,
inclusion: { in: %w[on_success on_failure always manual],
inclusion: { in: %w[on_success on_failure always manual delayed],
message: 'should be on_success, on_failure, ' \
'always or manual' }
......@@ -36,11 +36,11 @@ module Gitlab
validates :extends, type: String
with_options if: :manual_action? do
validates :autoplay_in, duration: true, allow_nil: true
validates :start_in, duration: true, allow_nil: true
end
with_options unless: :manual_action? do
validates :autoplay_in, presence: false
validates :start_in, presence: false
end
end
end
......@@ -92,7 +92,7 @@ module Gitlab
:artifacts, :commands, :environment, :coverage, :retry
attributes :script, :tags, :allow_failure, :when, :dependencies,
:retry, :extends, :autoplay_in
:retry, :extends, :start_in
def compose!(deps = nil)
super do
......@@ -119,7 +119,7 @@ module Gitlab
end
def manual_action?
self.when == 'manual'
self.when == 'manual' || self.when == 'delayed'
end
def ignored?
......
......@@ -2,7 +2,7 @@ module Gitlab
module Ci
module Status
module Build
class ManualWithAutoPlay < Status::Extended
class Delayed < Status::Extended
###
# TODO: Those are random values. We have to fix accoding to the UX review
###
......@@ -43,7 +43,7 @@ module Gitlab
end
def self.matches?(build, user)
build.autoplay? && !build.canceled?
build.delayed? && !build.canceled?
end
end
end
......
......@@ -5,7 +5,7 @@ module Gitlab
class Factory < Status::Factory
def self.extended_statuses
[[Status::Build::Erased,
Status::Build::ManualWithAutoPlay,
Status::Build::Delayed,
Status::Build::Manual,
Status::Build::Canceled,
Status::Build::Created,
......
......@@ -50,7 +50,7 @@ module Gitlab
after_script: job[:after_script],
environment: job[:environment],
retry: job[:retry],
autoplay_in: job[:autoplay_in],
start_in: job[:start_in],
}.compact }
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment