diff options
author | Kamil Trzciński <ayufan@ayufan.eu> | 2018-12-03 10:55:29 +0000 |
---|---|---|
committer | Kamil Trzciński <ayufan@ayufan.eu> | 2018-12-03 10:55:29 +0000 |
commit | 8a465b0c456e4f774f02ec1991d32549872f5684 (patch) | |
tree | 9d29352ed55081e6e3cd995fbf79dac9e09a5741 /app/models | |
parent | 76d4e6d6d87f3e59f1864fa15da701bb789e301e (diff) | |
parent | 4bd00e5378736231225394f80b87b7f89077cb76 (diff) | |
download | gitlab-ce-8a465b0c456e4f774f02ec1991d32549872f5684.tar.gz |
Merge branch 'fix-mr-widget-unrelated-deployment-status' into 'master'
Fix unrelated deployment status in MR widget
Closes #54125
See merge request gitlab-org/gitlab-ce!23175
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/ci/pipeline.rb | 6 | ||||
-rw-r--r-- | app/models/environment_status.rb | 14 |
2 files changed, 9 insertions, 11 deletions
diff --git a/app/models/ci/pipeline.rb b/app/models/ci/pipeline.rb index 9512ba42f67..1487b9d3bca 100644 --- a/app/models/ci/pipeline.rb +++ b/app/models/ci/pipeline.rb @@ -26,6 +26,8 @@ module Ci has_many :builds, foreign_key: :commit_id, inverse_of: :pipeline has_many :trigger_requests, dependent: :destroy, foreign_key: :commit_id # rubocop:disable Cop/ActiveRecordDependent has_many :variables, class_name: 'Ci::PipelineVariable' + has_many :deployments, through: :builds + has_many :environments, -> { distinct }, through: :deployments # Merge requests for which the current pipeline is running against # the merge request's latest commit. @@ -523,10 +525,6 @@ module Ci yaml_errors.present? end - def environments - builds.where.not(environment: nil).success.pluck(:environment).uniq - end - # Manually set the notes for a Ci::Pipeline # There is no ActiveRecord relation between Ci::Pipeline and notes # as they are related to a commit sha. This method helps importing diff --git a/app/models/environment_status.rb b/app/models/environment_status.rb index 4a128dde5cd..2fb6cadc8cd 100644 --- a/app/models/environment_status.rb +++ b/app/models/environment_status.rb @@ -12,13 +12,13 @@ class EnvironmentStatus delegate :deployed_at, to: :deployment, allow_nil: true def self.for_merge_request(mr, user) - build_environments_status(mr, user, mr.diff_head_sha) + build_environments_status(mr, user, mr.actual_head_pipeline) end def self.after_merge_request(mr, user) return [] unless mr.merged? - build_environments_status(mr, user, mr.merge_commit_sha) + build_environments_status(mr, user, mr.merge_pipeline) end def initialize(environment, merge_request, sha) @@ -61,13 +61,13 @@ class EnvironmentStatus } end - def self.build_environments_status(mr, user, sha) - Environment.where(project_id: [mr.source_project_id, mr.target_project_id]) - .available - .with_deployment(sha).map do |environment| + def self.build_environments_status(mr, user, pipeline) + return [] unless pipeline + + pipeline.environments.available.map do |environment| next unless Ability.allowed?(user, :read_environment, environment) - EnvironmentStatus.new(environment, mr, sha) + EnvironmentStatus.new(environment, mr, pipeline.sha) end.compact end private_class_method :build_environments_status |