Commit 1c248cd4 authored by Shinya Maeda's avatar Shinya Maeda

Fix unexpected exception by failed to find an actual head pipeline

Add changelog
parent b2e807e6
...@@ -1108,9 +1108,10 @@ class MergeRequest < ActiveRecord::Base ...@@ -1108,9 +1108,10 @@ class MergeRequest < ActiveRecord::Base
end end
def update_head_pipeline def update_head_pipeline
self.head_pipeline = find_actual_head_pipeline find_actual_head_pipeline.try do |pipeline|
self.head_pipeline = pipeline
update_column(:head_pipeline_id, head_pipeline.id) if head_pipeline_id_changed? update_column(:head_pipeline_id, head_pipeline.id) if head_pipeline_id_changed?
end
end end
def merge_request_pipeline_exists? def merge_request_pipeline_exists?
......
---
title: Fix unexpected exception by failure of finding an actual head pipeline
merge_request: 24257
author:
type: fixed
...@@ -1418,6 +1418,23 @@ describe MergeRequest do ...@@ -1418,6 +1418,23 @@ describe MergeRequest do
.to change { merge_request.reload.head_pipeline } .to change { merge_request.reload.head_pipeline }
.from(nil).to(pipeline) .from(nil).to(pipeline)
end end
context 'when merge request has already had head pipeline' do
before do
merge_request.update!(head_pipeline: pipeline)
end
context 'when failed to find an actual head pipeline' do
before do
allow(merge_request).to receive(:find_actual_head_pipeline) { }
end
it 'does not update the current head pipeline' do
expect { subject }
.not_to change { merge_request.reload.head_pipeline }
end
end
end
end end
context 'when there are no pipelines with the diff head sha' do context 'when there are no pipelines with the diff head sha' do
......
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