Commit dcda9b1e authored by Shinya Maeda's avatar Shinya Maeda

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
......@@ -425,6 +425,14 @@ class Environment < ApplicationRecord
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?
......
......@@ -16,7 +16,7 @@ module Deployments
# 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
......
......@@ -1710,4 +1710,36 @@ RSpec.describe Environment, :use_clean_rails_memory_store_caching do
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
......@@ -32,6 +32,19 @@ RSpec.describe Deployments::LinkMergeRequestsService do
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')
......
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