summaryrefslogtreecommitdiff
path: root/app/models/ci
diff options
context:
space:
mode:
Diffstat (limited to 'app/models/ci')
-rw-r--r--app/models/ci/build.rb24
-rw-r--r--app/models/ci/pipeline.rb4
2 files changed, 28 insertions, 0 deletions
diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb
index ffac3a22efc..81feca0088f 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).without_created }
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 playable_actions
+ pipeline.playable_actions
+ end
+
+ def playable?
+ project.builds_enabled? && commands.present? && manual?
+ end
+
+ def play(current_user = nil)
+ if skipped?
+ # We can run skipped build
+ new_build.user = current_user
+ new_build.queue
+ 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 b468434866b..5aefe1d1694 100644
--- a/app/models/ci/pipeline.rb
+++ b/app/models/ci/pipeline.rb
@@ -65,6 +65,10 @@ module Ci
!tag?
end
+ def playable_actions
+ builds.manual_actions.latest
+ end
+
def retryable?
builds.latest.any? do |build|
build.failed? && build.retryable?