diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-04-20 23:50:22 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-04-20 23:50:22 +0000 |
commit | 9dc93a4519d9d5d7be48ff274127136236a3adb3 (patch) | |
tree | 70467ae3692a0e35e5ea56bcb803eb512a10bedb /app/models/deployment.rb | |
parent | 4b0f34b6d759d6299322b3a54453e930c6121ff0 (diff) | |
download | gitlab-ce-9dc93a4519d9d5d7be48ff274127136236a3adb3.tar.gz |
Add latest changes from gitlab-org/gitlab@13-11-stable-eev13.11.0-rc43
Diffstat (limited to 'app/models/deployment.rb')
-rw-r--r-- | app/models/deployment.rb | 33 |
1 files changed, 9 insertions, 24 deletions
diff --git a/app/models/deployment.rb b/app/models/deployment.rb index f000e474605..d3280403bfd 100644 --- a/app/models/deployment.rb +++ b/app/models/deployment.rb @@ -45,6 +45,7 @@ class Deployment < ApplicationRecord scope :active, -> { where(status: %i[created running]) } 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) } + scope :with_api_entity_associations, -> { preload({ deployable: { runner: [], tags: [], user: [], job_artifacts_archive: [] } }) } scope :finished_after, ->(date) { where('finished_at >= ?', date) } scope :finished_before, ->(date) { where('finished_at < ?', date) } @@ -93,11 +94,6 @@ class Deployment < ApplicationRecord after_transition any => :success do |deployment| deployment.run_after_commit do Deployments::UpdateEnvironmentWorker.perform_async(id) - end - end - - after_transition any => FINISHED_STATUSES do |deployment| - deployment.run_after_commit do Deployments::LinkMergeRequestWorker.perform_async(id) end end @@ -175,7 +171,7 @@ class Deployment < ApplicationRecord end def commit - project.commit(sha) + @commit ||= project.commit(sha) end def commit_title @@ -225,7 +221,7 @@ class Deployment < ApplicationRecord end def update_merge_request_metrics! - return unless environment.update_merge_request_metrics? && success? + return unless environment.production? && success? merge_requests = project.merge_requests .joins(:metrics) @@ -243,29 +239,18 @@ class Deployment < ApplicationRecord def previous_deployment @previous_deployment ||= - project.deployments.joins(:environment) - .where(environments: { name: self.environment.name }, ref: self.ref) - .where.not(id: self.id) - .order(id: :desc) - .take - end - - def previous_environment_deployment - project - .deployments - .success - .joins(:environment) - .where(environments: { name: environment.name }) - .where.not(id: self.id) - .order(id: :desc) - .take + self.class.for_environment(environment_id) + .success + .where('id < ?', id) + .order(id: :desc) + .take end def stop_action return unless on_stop.present? return unless manual_actions - @stop_action ||= manual_actions.find_by(name: on_stop) + @stop_action ||= manual_actions.find { |action| action.name == self.on_stop } end def finished_at |