Commit be039d22 authored by Kamil Trzcinski's avatar Kamil Trzcinski Committed by Grzegorz Bizon

Make manual actions blocking

parent 6cc02e08
......@@ -63,6 +63,10 @@ module Ci
end
state_machine :status do
event :block do
transition :created => :manual, if: () -> { self.when == 'manual' }
end
after_transition any => [:pending] do |build|
build.run_after_commit do
BuildQueueWorker.perform_async(id)
......@@ -94,16 +98,16 @@ module Ci
.fabricate!
end
def manual?
self.when == 'manual'
end
def other_actions
pipeline.manual_actions.where.not(name: name)
end
def playable?
project.builds_enabled? && commands.present? && manual? && skipped?
project.builds_enabled? && commands.present? && manual?
end
def is_blocking?
playable? && !allow_failure?
end
def play(current_user)
......
......@@ -25,13 +25,13 @@ class CommitStatus < ActiveRecord::Base
end
scope :failed_but_allowed, -> do
where(allow_failure: true, status: [:failed, :canceled])
where(allow_failure: true, status: [:failed, :canceled, :manual])
end
scope :exclude_ignored, -> do
# We want to ignore failed_but_allowed jobs
where("allow_failure = ? OR status IN (?)",
false, all_state_names - [:failed, :canceled])
false, all_state_names - [:failed, :canceled, :manual])
end
scope :retried, -> { where.not(id: latest) }
......@@ -42,11 +42,11 @@ class CommitStatus < ActiveRecord::Base
state_machine :status do
event :enqueue do
transition [:created, :skipped] => :pending
transition [:created, :skipped, :manual] => :pending
end
event :process do
transition skipped: :created
transition [:skipped, :manual] => :created
end
event :run do
......@@ -66,7 +66,7 @@ class CommitStatus < ActiveRecord::Base
end
event :cancel do
transition [:created, :pending, :running] => :canceled
transition [:created, :pending, :running, :manual] => :canceled
end
before_transition created: [:pending, :running] do |commit_status|
......
......@@ -2,9 +2,9 @@ module HasStatus
extend ActiveSupport::Concern
DEFAULT_STATUS = 'created'.freeze
AVAILABLE_STATUSES = %w[created pending running success failed canceled skipped].freeze
AVAILABLE_STATUSES = %w[created pending running success failed canceled skipped manual].freeze
STARTED_STATUSES = %w[running success failed skipped].freeze
ACTIVE_STATUSES = %w[pending running].freeze
ACTIVE_STATUSES = %w[pending running manual].freeze
COMPLETED_STATUSES = %w[success failed canceled skipped].freeze
ORDERED_STATUSES = %w[failed pending running canceled success skipped].freeze
......@@ -18,6 +18,7 @@ module HasStatus
builds = scope.select('count(*)').to_sql
created = scope.created.select('count(*)').to_sql
success = scope.success.select('count(*)').to_sql
manual = scope.manual.select('count(*)').to_sql
pending = scope.pending.select('count(*)').to_sql
running = scope.running.select('count(*)').to_sql
skipped = scope.skipped.select('count(*)').to_sql
......@@ -31,6 +32,7 @@ module HasStatus
WHEN (#{builds})=(#{success})+(#{skipped})+(#{canceled}) THEN 'canceled'
WHEN (#{builds})=(#{created})+(#{skipped})+(#{pending}) THEN 'pending'
WHEN (#{running})+(#{pending})+(#{created})>0 THEN 'running'
WHEN (#{manual})>0 THEN 'manual'
ELSE 'failed'
END)"
end
......@@ -63,6 +65,7 @@ module HasStatus
state :success, value: 'success'
state :canceled, value: 'canceled'
state :skipped, value: 'skipped'
state :manual, value: 'manual'
end
scope :created, -> { where(status: 'created') }
......@@ -73,12 +76,13 @@ module HasStatus
scope :failed, -> { where(status: 'failed') }
scope :canceled, -> { where(status: 'canceled') }
scope :skipped, -> { where(status: 'skipped') }
scope :manual, -> { where(status: 'manual') }
scope :running_or_pending, -> { where(status: [:running, :pending]) }
scope :finished, -> { where(status: [:success, :failed, :canceled]) }
scope :failed_or_canceled, -> { where(status: [:failed, :canceled]) }
scope :cancelable, -> do
where(status: [:running, :pending, :created])
where(status: [:running, :pending, :created, :manual])
end
end
......
......@@ -12,7 +12,7 @@ class BuildEntity < Grape::Entity
path_to(:retry_namespace_project_build, build)
end
expose :play_path, if: ->(build, _) { build.manual? } do |build|
expose :play_path, if: ->(build, _) { build.playable? } do |build|
path_to(:play_namespace_project_build, build)
end
......
......@@ -35,6 +35,9 @@ module Ci
if valid_statuses_for_when(build.when).include?(current_status)
build.enqueue
true
elsif build.can_block?
build.block
build.is_blocking?
else
build.skip
false
......
......@@ -104,6 +104,10 @@ module Gitlab
(before_script_value.to_a + script_value.to_a).join("\n")
end
def allow_failure
super || self.when == 'manual'
end
private
def inherit!(deps)
......
module Gitlab
module Ci
module Status
class Manual < Status::Core
def text
'manual'
end
def label
'manual'
end
def icon
'icon_status_manual'
end
end
end
end
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