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,14 +44,15 @@ ...@@ -44,14 +44,15 @@
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|
.mr-widget-heading - if can?(current_user, :read_environment, environment)
.ci_widget.ci-success .mr-widget-heading
= ci_icon_for_status("success") .ci_widget.ci-success
%span.hidden-sm = ci_icon_for_status("success")
Deployed to %span.hidden-sm
= succeed '.' do Deployed to
= link_to environment.name, namespace_project_environment_path(@project.namespace, @project, environment), class: 'environment' = succeed '.' do
- external_url = environment.external_url = link_to environment.name, namespace_project_environment_path(@project.namespace, @project, environment), class: 'environment'
- if external_url - external_url = environment.external_url
= link_to external_url, target: '_blank' do - if external_url
= icon('external-link', text: "View on #{external_url.gsub(/\A.*?:\/\//, '')}", right: true) = link_to external_url, target: '_blank' do
= icon('external-link', text: "View on #{external_url.gsub(/\A.*?:\/\//, '')}", right: true)
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