Commit 28ef9e89 authored by Tetiana Chupryna's avatar Tetiana Chupryna

Merge branch 'fix-deployment-merge-request-relationship-creation' into 'master'

Fix deployment merge request link creation

See merge request gitlab-org/gitlab!72757
parents c18a4e74 dcda9b1e
...@@ -425,6 +425,14 @@ class Environment < ApplicationRecord ...@@ -425,6 +425,14 @@ class Environment < ApplicationRecord
clear_reactive_cache! clear_reactive_cache!
end end
def should_link_to_merge_requests?
unfoldered? || production? || staging?
end
def unfoldered?
environment_type.nil?
end
private private
def rollout_status_available? def rollout_status_available?
......
...@@ -16,7 +16,7 @@ module Deployments ...@@ -16,7 +16,7 @@ module Deployments
# Review apps have the environment type set (e.g. to `review`, though the # 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 # exact value may differ). We don't want to link merge requests to review
# app deployments, as this is not useful. # 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 # 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 # 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 ...@@ -1710,4 +1710,36 @@ RSpec.describe Environment, :use_clean_rails_memory_store_caching do
subject subject
end end
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 end
...@@ -32,6 +32,19 @@ RSpec.describe Deployments::LinkMergeRequestsService do ...@@ -32,6 +32,19 @@ RSpec.describe Deployments::LinkMergeRequestsService do
end end
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 context 'when the deployment failed' do
it 'does nothing' do it 'does nothing' do
environment = create(:environment, name: 'foo') 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