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