Skip to content
Snippets Groups Projects
Commit 0c72cf5a authored by Alessio Caiazza's avatar Alessio Caiazza
Browse files

expose post merge environments

parent 88d08f75
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -204,11 +204,17 @@ class Projects::MergeRequestsController < Projects::MergeRequests::ApplicationCo
end
 
def ci_environments_status
sha = if ci_environments_status_on_merge_result?
@merge_request.merge_commit_sha
else
@merge_request.diff_head_sha
end
environments =
begin
@merge_request.environments_for(current_user).map do |environment|
@merge_request.environments_for(current_user, post_merge: ci_environments_status_on_merge_result?).map do |environment|
project = environment.project
deployment = environment.first_deployment_for(@merge_request.diff_head_sha)
deployment = environment.first_deployment_for(sha)
 
stop_url =
if can?(current_user, :stop_environment, environment)
Loading
Loading
@@ -274,6 +280,10 @@ class Projects::MergeRequestsController < Projects::MergeRequests::ApplicationCo
end
end
 
def ci_environments_status_on_merge_result?
params[:target] == 'merge'
end
private
 
def target_branch_missing?
Loading
Loading
Loading
Loading
@@ -953,16 +953,17 @@ class MergeRequest < ActiveRecord::Base
actual_head_pipeline&.success? || actual_head_pipeline&.skipped?
end
 
def environments_for(current_user)
return [] unless diff_head_commit
def environments_for(current_user, post_merge: false)
commit = post_merge ? merge_commit : diff_head_commit
return [] unless commit
 
@environments ||= Hash.new do |h, current_user|
envs = EnvironmentsFinder.new(target_project, current_user,
ref: target_branch, commit: diff_head_commit, with_tags: true).execute
ref: target_branch, commit: commit, with_tags: true).execute
 
if source_project
envs.concat EnvironmentsFinder.new(source_project, current_user,
ref: source_branch, commit: diff_head_commit).execute
ref: source_branch, commit: commit).execute
end
 
h[current_user] = envs.uniq
Loading
Loading
Loading
Loading
@@ -778,6 +778,14 @@ describe Projects::MergeRequestsController do
expect(json_response.first['url']).to match /#{forked.full_path}/
end
 
context "when target is 'merge'" do
it 'returns nothing' do
get_ci_environments_status(target: 'merge')
expect(json_response).to be_empty
end
end
# we're trying to reduce the overall number of queries for this method.
# set a hard limit for now. https://gitlab.com/gitlab-org/gitlab-ce/issues/52287
it 'keeps queries in check' do
Loading
Loading
@@ -786,11 +794,15 @@ describe Projects::MergeRequestsController do
expect(control_count).to be <= 137
end
 
def get_ci_environments_status
get :ci_environments_status,
def get_ci_environments_status(extra_params = {})
params = {
namespace_id: merge_request.project.namespace.to_param,
project_id: merge_request.project,
id: merge_request.iid, format: 'json'
id: merge_request.iid,
format: 'json'
}
get :ci_environments_status, params.merge(extra_params)
end
end
end
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment