diff options
Diffstat (limited to 'app/models/deployment.rb')
-rw-r--r-- | app/models/deployment.rb | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/app/models/deployment.rb b/app/models/deployment.rb index 36ac1bdb236..ad741366a74 100644 --- a/app/models/deployment.rb +++ b/app/models/deployment.rb @@ -41,8 +41,8 @@ class Deployment < ApplicationRecord scope :visible, -> { where(status: %i[running success failed canceled]) } scope :stoppable, -> { where.not(on_stop: nil).where.not(deployable_id: nil).success } scope :active, -> { where(status: %i[created running]) } - scope :older_than, -> (deployment) { where('id < ?', deployment.id) } - scope :with_deployable, -> { includes(:deployable).where('deployable_id IS NOT NULL') } + scope :older_than, -> (deployment) { where('deployments.id < ?', deployment.id) } + scope :with_deployable, -> { joins('INNER JOIN ci_builds ON ci_builds.id = deployments.deployable_id').preload(:deployable) } FINISHED_STATUSES = %i[success failed canceled].freeze @@ -63,6 +63,10 @@ class Deployment < ApplicationRecord transition any - [:canceled] => :canceled end + event :skip do + transition any - [:skipped] => :skipped + end + before_transition any => FINISHED_STATUSES do |deployment| deployment.finished_at = Time.current end @@ -105,7 +109,8 @@ class Deployment < ApplicationRecord running: 1, success: 2, failed: 3, - canceled: 4 + canceled: 4, + skipped: 5 } def self.last_for_environment(environment) @@ -144,6 +149,10 @@ class Deployment < ApplicationRecord project.repository.delete_refs(*ref_paths.flatten) end end + + def latest_for_sha(sha) + where(sha: sha).order(id: :desc).take + end end def commit @@ -297,6 +306,8 @@ class Deployment < ApplicationRecord drop when 'canceled' cancel + when 'skipped' + skip else raise ArgumentError, "The status #{status.inspect} is invalid" end |