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
def environments
return [] unless diff_head_commit
target_project.environments.select do |environment|
environment.includes_commit?(diff_head_commit)
end
environments = source_project.environments_for(
source_branch, diff_head_commit)
environments <<= target_project.environments_for(
source_branch, diff_head_commit, with_tags: true)
environments
end
def state_human_name
......
......@@ -1293,6 +1293,22 @@ class Project < ActiveRecord::Base
Gitlab::Redis.with { |redis| redis.del(pushes_since_gc_redis_key) }
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
def pushes_since_gc_redis_key
......
......@@ -44,14 +44,15 @@
Could not connect to the CI server. Please check your settings and try again.
- @merge_request.environments.each do |environment|
.mr-widget-heading
.ci_widget.ci-success
= ci_icon_for_status("success")
%span.hidden-sm
Deployed to
= succeed '.' do
= link_to environment.name, namespace_project_environment_path(@project.namespace, @project, environment), class: 'environment'
- external_url = environment.external_url
- if external_url
= link_to external_url, target: '_blank' do
= icon('external-link', text: "View on #{external_url.gsub(/\A.*?:\/\//, '')}", right: true)
- if can?(current_user, :read_environment, environment)
.mr-widget-heading
.ci_widget.ci-success
= ci_icon_for_status("success")
%span.hidden-sm
Deployed to
= succeed '.' do
= link_to environment.name, namespace_project_environment_path(@project.namespace, @project, environment), class: 'environment'
- external_url = environment.external_url
- if external_url
= 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