Skip to content

Commit 3ce491c

Browse files
committed
Merge branch 'fix-udpate-head-pipeline-method' into 'master'
Fix unexpected exception by failure of finding an actual head pipeline Closes #56113 See merge request gitlab-org/gitlab-ce!24257
2 parents 0f71b4b + 1c248cd commit 3ce491c

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

app/models/merge_request.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1108,9 +1108,10 @@ def all_pipelines(shas: all_commit_shas)
11081108
end
11091109

11101110
def update_head_pipeline
1111-
self.head_pipeline = find_actual_head_pipeline
1112-
1113-
update_column(:head_pipeline_id, head_pipeline.id) if head_pipeline_id_changed?
1111+
find_actual_head_pipeline.try do |pipeline|
1112+
self.head_pipeline = pipeline
1113+
update_column(:head_pipeline_id, head_pipeline.id) if head_pipeline_id_changed?
1114+
end
11141115
end
11151116

11161117
def merge_request_pipeline_exists?
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
title: Fix unexpected exception by failure of finding an actual head pipeline
3+
merge_request: 24257
4+
author:
5+
type: fixed

spec/models/merge_request_spec.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1418,6 +1418,23 @@ def set_compare(merge_request)
14181418
.to change { merge_request.reload.head_pipeline }
14191419
.from(nil).to(pipeline)
14201420
end
1421+
1422+
context 'when merge request has already had head pipeline' do
1423+
before do
1424+
merge_request.update!(head_pipeline: pipeline)
1425+
end
1426+
1427+
context 'when failed to find an actual head pipeline' do
1428+
before do
1429+
allow(merge_request).to receive(:find_actual_head_pipeline) { }
1430+
end
1431+
1432+
it 'does not update the current head pipeline' do
1433+
expect { subject }
1434+
.not_to change { merge_request.reload.head_pipeline }
1435+
end
1436+
end
1437+
end
14211438
end
14221439

14231440
context 'when there are no pipelines with the diff head sha' do

0 commit comments

Comments
 (0)