Skip to content
Snippets Groups Projects
Commit dcda9b1e authored by Shinya Maeda's avatar Shinya Maeda
Browse files

Fix deployment merge request link creation

This commit fixes the deployment and merge request link
creation that it ignores production grade environments if it's
foldered.

Changelog: fixed
parent 270c6c4a
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -425,6 +425,14 @@ def clear_all_caches
clear_reactive_cache!
end
 
def should_link_to_merge_requests?
unfoldered? || production? || staging?
end
def unfoldered?
environment_type.nil?
end
private
 
def rollout_status_available?
Loading
Loading
Loading
Loading
@@ -16,7 +16,7 @@ def execute
# Review apps have the environment type set (e.g. to `review`, though the
# exact value may differ). We don't want to link merge requests to review
# app deployments, as this is not useful.
return if deployment.environment.environment_type
return unless deployment.environment.should_link_to_merge_requests?
 
# This service is triggered by a Sidekiq worker, which only runs when a
# deployment is successful. We add an extra check here in case we ever
Loading
Loading
Loading
Loading
@@ -1710,4 +1710,36 @@
subject
end
end
describe '#should_link_to_merge_requests?' do
subject { environment.should_link_to_merge_requests? }
context 'when environment is foldered' do
context 'when environment is production tier' do
let(:environment) { create(:environment, project: project, name: 'production/aws') }
it { is_expected.to eq(true) }
end
context 'when environment is development tier' do
let(:environment) { create(:environment, project: project, name: 'review/feature') }
it { is_expected.to eq(false) }
end
end
context 'when environment is unfoldered' do
context 'when environment is production tier' do
let(:environment) { create(:environment, project: project, name: 'production') }
it { is_expected.to eq(true) }
end
context 'when environment is development tier' do
let(:environment) { create(:environment, project: project, name: 'development') }
it { is_expected.to eq(true) }
end
end
end
end
Loading
Loading
@@ -32,6 +32,19 @@
end
end
 
context 'when the deployment is for one of the production environments' do
it 'links merge requests' do
environment =
create(:environment, environment_type: 'production', name: 'production/gcp')
deploy = create(:deployment, :success, environment: environment)
expect(deploy).to receive(:link_merge_requests).once
described_class.new(deploy).execute
end
end
context 'when the deployment failed' do
it 'does nothing' do
environment = create(:environment, name: 'foo')
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