From ac5bd3b73c0255bb9307913a2d4338d0a431cac6 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Fri, 3 Mar 2017 14:35:19 +0100 Subject: [PATCH] Reinstitute a core `manual` status for manual actions --- app/models/ci/build.rb | 14 +++++++------- app/models/ci/pipeline.rb | 4 ++-- app/models/commit_status.rb | 12 ++++++------ app/models/concerns/has_status.rb | 18 +++++++++--------- app/services/ci/process_pipeline_service.rb | 4 ++-- app/views/projects/ci/builds/_build.html.haml | 2 +- lib/gitlab/ci/status/{blocked.rb => manual.rb} | 6 +++--- lib/gitlab/data_builder/pipeline.rb | 2 +- spec/models/ci/build_spec.rb | 4 ++-- .../ci/process_pipeline_service_spec.rb | 4 ++-- 10 files changed, 35 insertions(+), 35 deletions(-) rename lib/gitlab/ci/status/{blocked.rb => manual.rb} (70%) diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb index dde102f414a..93dbc6957a6 100644 --- a/app/models/ci/build.rb +++ b/app/models/ci/build.rb @@ -63,8 +63,8 @@ module Ci end state_machine :status do - event :block do - transition created: :blocked + event :actionize do + transition created: :manual end after_transition any => [:pending] do |build| @@ -103,16 +103,16 @@ module Ci end def playable? - project.builds_enabled? && has_commands? && manual? && - (skipped? || blocked?) + project.builds_enabled? && has_commands? && + action? && manual? end - def manual? + def action? self.when == 'manual' end def barrier? - manual? && !allow_failure? + action? && !allow_failure? end def has_commands? @@ -565,7 +565,7 @@ module Ci ] variables << { key: 'CI_BUILD_TAG', value: ref, public: true } if tag? variables << { key: 'CI_BUILD_TRIGGERED', value: 'true', public: true } if trigger_request - variables << { key: 'CI_BUILD_MANUAL', value: 'true', public: true } if manual? + variables << { key: 'CI_BUILD_MANUAL', value: 'true', public: true } if action? variables end diff --git a/app/models/ci/pipeline.rb b/app/models/ci/pipeline.rb index b0ca3e9c189..67206415f7b 100644 --- a/app/models/ci/pipeline.rb +++ b/app/models/ci/pipeline.rb @@ -50,7 +50,7 @@ module Ci end event :block do - transition any - [:blocked] => :blocked + transition any - [:manual] => :manual end # IMPORTANT @@ -325,7 +325,7 @@ module Ci when 'failed' then drop when 'canceled' then cancel when 'skipped' then skip - when 'blocked' then block + when 'manual' then block end end end diff --git a/app/models/commit_status.rb b/app/models/commit_status.rb index 9cdabf24677..6518f54cdff 100644 --- a/app/models/commit_status.rb +++ b/app/models/commit_status.rb @@ -25,13 +25,13 @@ class CommitStatus < ActiveRecord::Base end scope :failed_but_allowed, -> do - where(allow_failure: true, status: [:failed, :canceled, :blocked]) + 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, :blocked]) + 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, :blocked] => :pending + transition [:created, :skipped, :manual] => :pending end event :process do - transition [:skipped, :blocked] => :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, :blocked] => :canceled + transition [:created, :pending, :running, :manual] => :canceled end before_transition created: [:pending, :running] do |commit_status| @@ -86,7 +86,7 @@ class CommitStatus < ActiveRecord::Base commit_status.run_after_commit do pipeline.try do |pipeline| - if complete? || blocked? + if complete? || manual? PipelineProcessWorker.perform_async(pipeline.id) else PipelineUpdateWorker.perform_async(pipeline.id) diff --git a/app/models/concerns/has_status.rb b/app/models/concerns/has_status.rb index 2b559d8e828..a20e5bb6be6 100644 --- a/app/models/concerns/has_status.rb +++ b/app/models/concerns/has_status.rb @@ -2,12 +2,12 @@ module HasStatus extend ActiveSupport::Concern DEFAULT_STATUS = 'created'.freeze - BLOCKED_STATUS = 'blocked'.freeze - AVAILABLE_STATUSES = %w[created pending running success failed canceled skipped blocked].freeze + BLOCKED_STATUS = 'manual'.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 blocked].freeze + ACTIVE_STATUSES = %w[pending running manual].freeze COMPLETED_STATUSES = %w[success failed canceled skipped].freeze - ORDERED_STATUSES = %w[blocked failed pending running canceled success skipped].freeze + ORDERED_STATUSES = %w[manual failed pending running canceled success skipped].freeze class_methods do def status_sql @@ -16,7 +16,7 @@ module HasStatus builds = scope.select('count(*)').to_sql created = scope.created.select('count(*)').to_sql success = scope.success.select('count(*)').to_sql - blocked = scope.blocked.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 @@ -30,7 +30,7 @@ module HasStatus WHEN (#{builds})=(#{success})+(#{skipped})+(#{canceled}) THEN 'canceled' WHEN (#{builds})=(#{created})+(#{skipped})+(#{pending}) THEN 'pending' WHEN (#{running})+(#{pending})>0 THEN 'running' - WHEN (#{blocked})>0 THEN 'blocked' + WHEN (#{manual})>0 THEN 'manual' ELSE 'failed' END)" end @@ -63,7 +63,7 @@ module HasStatus state :success, value: 'success' state :canceled, value: 'canceled' state :skipped, value: 'skipped' - state :blocked, value: 'blocked' + state :manual, value: 'manual' end scope :created, -> { where(status: 'created') } @@ -74,13 +74,13 @@ module HasStatus scope :failed, -> { where(status: 'failed') } scope :canceled, -> { where(status: 'canceled') } scope :skipped, -> { where(status: 'skipped') } - scope :blocked, -> { where(status: 'blocked') } + 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, :blocked]) + where(status: [:running, :pending, :created, :manual]) end end diff --git a/app/services/ci/process_pipeline_service.rb b/app/services/ci/process_pipeline_service.rb index 30fccbddc33..c70b75cc577 100644 --- a/app/services/ci/process_pipeline_service.rb +++ b/app/services/ci/process_pipeline_service.rb @@ -37,8 +37,8 @@ module Ci if valid_statuses_for_when(build.when).include?(current_status) build.enqueue true - elsif build.barrier? - build.block + elsif build.action? && build.barrier? + build.actionize false else build.skip diff --git a/app/views/projects/ci/builds/_build.html.haml b/app/views/projects/ci/builds/_build.html.haml index 5ea85f9fd4c..09286a1b3c6 100644 --- a/app/views/projects/ci/builds/_build.html.haml +++ b/app/views/projects/ci/builds/_build.html.haml @@ -46,7 +46,7 @@ %span.label.label-info triggered - if build.try(:allow_failure) %span.label.label-danger allowed to fail - - if build.manual? + - if build.action? %span.label.label-info manual - if pipeline_link diff --git a/lib/gitlab/ci/status/blocked.rb b/lib/gitlab/ci/status/manual.rb similarity index 70% rename from lib/gitlab/ci/status/blocked.rb rename to lib/gitlab/ci/status/manual.rb index d17f4ea77b9..5f28521901d 100644 --- a/lib/gitlab/ci/status/blocked.rb +++ b/lib/gitlab/ci/status/manual.rb @@ -1,13 +1,13 @@ module Gitlab module Ci module Status - class Blocked < Status::Core + class Manual < Status::Core def text - 'blocked' + 'manual' end def label - 'blocked action' + 'manual action' end def icon diff --git a/lib/gitlab/data_builder/pipeline.rb b/lib/gitlab/data_builder/pipeline.rb index e50e54b6e99..182a30fd74d 100644 --- a/lib/gitlab/data_builder/pipeline.rb +++ b/lib/gitlab/data_builder/pipeline.rb @@ -39,7 +39,7 @@ module Gitlab started_at: build.started_at, finished_at: build.finished_at, when: build.when, - manual: build.manual?, + manual: build.action?, user: build.user.try(:hook_attrs), runner: build.runner && runner_hook_attrs(build.runner), artifacts_file: { diff --git a/spec/models/ci/build_spec.rb b/spec/models/ci/build_spec.rb index 5743c555cbe..e58f098bf44 100644 --- a/spec/models/ci/build_spec.rb +++ b/spec/models/ci/build_spec.rb @@ -682,12 +682,12 @@ describe Ci::Build, :models do end end - describe '#manual?' do + describe '#action?' do before do build.update(when: value) end - subject { build.manual? } + subject { build.action? } context 'when is set to manual' do let(:value) { 'manual' } diff --git a/spec/services/ci/process_pipeline_service_spec.rb b/spec/services/ci/process_pipeline_service_spec.rb index 31835d6836c..b38feaca69b 100644 --- a/spec/services/ci/process_pipeline_service_spec.rb +++ b/spec/services/ci/process_pipeline_service_spec.rb @@ -285,8 +285,8 @@ describe Ci::ProcessPipelineService, '#execute', :services do succeed_running_or_pending expect(builds_names).to eq %w[code:test staging:deploy] - expect(builds_statuses).to eq %w[success blocked] - expect(pipeline.reload.status).to eq 'blocked' + expect(builds_statuses).to eq %w[success manual] + expect(pipeline.reload).to be_manual end end