diff options
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/ci/build.rb | 24 | ||||
-rw-r--r-- | app/models/ci/pipeline.rb | 4 | ||||
-rw-r--r-- | app/models/commit_status.rb | 4 | ||||
-rw-r--r-- | app/models/concerns/statuseable.rb | 6 | ||||
-rw-r--r-- | app/models/deployment.rb | 4 |
5 files changed, 39 insertions, 3 deletions
diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb index ffac3a22efc..49a123d488b 100644 --- a/app/models/ci/build.rb +++ b/app/models/ci/build.rb @@ -15,6 +15,7 @@ module Ci scope :with_artifacts, ->() { where.not(artifacts_file: nil) } scope :with_expired_artifacts, ->() { with_artifacts.where('artifacts_expire_at < ?', Time.now) } scope :last_month, ->() { where('created_at > ?', Date.today - 1.month) } + scope :manual_actions, ->() { where(when: :manual) } mount_uploader :artifacts_file, ArtifactUploader mount_uploader :artifacts_metadata, ArtifactUploader @@ -91,6 +92,29 @@ module Ci end end + def manual? + self.when == 'manual' + end + + def other_actions + pipeline.manual_actions.where.not(id: self) + end + + def playable? + project.builds_enabled? && commands.present? && manual? + end + + def play(current_user = nil) + # Try to queue a current build + if self.queue + self.update(user: current_user) + self + else + # Otherwise we need to create a duplicate + Ci::Build.retry(self, current_user) + end + end + def retryable? project.builds_enabled? && commands.present? && complete? end diff --git a/app/models/ci/pipeline.rb b/app/models/ci/pipeline.rb index a65a826536d..aca8607f4e8 100644 --- a/app/models/ci/pipeline.rb +++ b/app/models/ci/pipeline.rb @@ -69,6 +69,10 @@ module Ci !tag? end + def manual_actions + builds.latest.manual_actions + end + def retryable? builds.latest.any? do |build| build.failed? && build.retryable? diff --git a/app/models/commit_status.rb b/app/models/commit_status.rb index e437e3417a8..535db26240a 100644 --- a/app/models/commit_status.rb +++ b/app/models/commit_status.rb @@ -22,6 +22,10 @@ class CommitStatus < ActiveRecord::Base scope :ignored, -> { where(allow_failure: true, status: [:failed, :canceled]) } state_machine :status, initial: :pending do + event :queue do + transition skipped: :pending + end + event :run do transition pending: :running end diff --git a/app/models/concerns/statuseable.rb b/app/models/concerns/statuseable.rb index 3ef91caad47..44c6b30f278 100644 --- a/app/models/concerns/statuseable.rb +++ b/app/models/concerns/statuseable.rb @@ -16,10 +16,10 @@ module Statuseable deduce_status = "(CASE WHEN (#{builds})=0 THEN NULL - WHEN (#{builds})=(#{success})+(#{ignored}) THEN 'success' - WHEN (#{builds})=(#{pending}) THEN 'pending' - WHEN (#{builds})=(#{canceled})+(#{success})+(#{ignored}) THEN 'canceled' WHEN (#{builds})=(#{skipped}) THEN 'skipped' + WHEN (#{builds})=(#{success})+(#{ignored})+(#{skipped}) THEN 'success' + WHEN (#{builds})=(#{pending})+(#{skipped}) THEN 'pending' + WHEN (#{builds})=(#{canceled})+(#{success})+(#{ignored})+(#{skipped}) THEN 'canceled' WHEN (#{running})+(#{pending})>0 THEN 'running' ELSE 'failed' END)" diff --git a/app/models/deployment.rb b/app/models/deployment.rb index 520026c18dd..1a7cd60817e 100644 --- a/app/models/deployment.rb +++ b/app/models/deployment.rb @@ -32,4 +32,8 @@ class Deployment < ActiveRecord::Base def keep_around_commit project.repository.keep_around(self.sha) end + + def manual_actions + deployable.try(:other_actions) + end end |