Commit d891051c authored by Kamil Trzcinski's avatar Kamil Trzcinski

Limit number of shown environments for Merge Requests

- For target project show only environments for target branch or with tags
- For source project show only environments for source branch
parent 5416ab8a
...@@ -670,9 +670,12 @@ class MergeRequest < ActiveRecord::Base ...@@ -670,9 +670,12 @@ class MergeRequest < ActiveRecord::Base
def environments def environments
return [] unless diff_head_commit return [] unless diff_head_commit
target_project.environments.select do |environment| environments = source_project.environments_for(
environment.includes_commit?(diff_head_commit) source_branch, diff_head_commit)
end environments <<= target_project.environments_for(
source_branch, diff_head_commit, with_tags: true)
environments
end end
def state_human_name def state_human_name
......
...@@ -1293,6 +1293,22 @@ class Project < ActiveRecord::Base ...@@ -1293,6 +1293,22 @@ class Project < ActiveRecord::Base
Gitlab::Redis.with { |redis| redis.del(pushes_since_gc_redis_key) } Gitlab::Redis.with { |redis| redis.del(pushes_since_gc_redis_key) }
end end
def environments_for(ref, commit, with_tags: false)
environment_ids = deployments.group(:environment_id).
select(:environment_id)
environment_ids =
if with_tags
environment_ids.where('ref=? OR tag IS TRUE', ref)
else
environment_ids.where(ref: ref)
end
Environment.where(id: environment_ids).map do |environment|
environment.includes_commit?(commit)
end
end
private private
def pushes_since_gc_redis_key def pushes_since_gc_redis_key
......
...@@ -44,6 +44,7 @@ ...@@ -44,6 +44,7 @@
Could not connect to the CI server. Please check your settings and try again. Could not connect to the CI server. Please check your settings and try again.
- @merge_request.environments.each do |environment| - @merge_request.environments.each do |environment|
- if can?(current_user, :read_environment, environment)
.mr-widget-heading .mr-widget-heading
.ci_widget.ci-success .ci_widget.ci-success
= ci_icon_for_status("success") = ci_icon_for_status("success")
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment