diff options
author | Grzegorz Bizon <grzegorz@gitlab.com> | 2019-01-11 13:30:25 +0000 |
---|---|---|
committer | GitLab Release Tools Bot <robert+release-tools@gitlab.com> | 2019-01-14 23:59:47 +0000 |
commit | 740f64c77b5621356be5fe8ff48aa08b860d9c0b (patch) | |
tree | 86303a6a14e7cb275bb2db2998c22b99d63f13c9 | |
parent | f623c2f2d9376d2c7b4f5fc2427f3fd4c6ca8844 (diff) | |
download | gitlab-ce-740f64c77b5621356be5fe8ff48aa08b860d9c0b.tar.gz |
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
(cherry picked from commit 3ce491c5a065be80856e1f8d5097caba7ea8dd5d)
1c248cd4 Fix unexpected exception by failed to find an actual head pipeline
-rw-r--r-- | app/models/merge_request.rb | 7 | ||||
-rw-r--r-- | changelogs/unreleased/fix-udpate-head-pipeline-method.yml | 5 | ||||
-rw-r--r-- | spec/models/merge_request_spec.rb | 17 |
3 files changed, 26 insertions, 3 deletions
diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb index f220fa705ce..237b01636fb 100644 --- a/app/models/merge_request.rb +++ b/app/models/merge_request.rb @@ -1102,9 +1102,10 @@ class MergeRequest < ActiveRecord::Base end def update_head_pipeline - self.head_pipeline = find_actual_head_pipeline - - update_column(:head_pipeline_id, head_pipeline.id) if head_pipeline_id_changed? + find_actual_head_pipeline.try do |pipeline| + self.head_pipeline = pipeline + update_column(:head_pipeline_id, head_pipeline.id) if head_pipeline_id_changed? + end end def merge_request_pipeline_exists? diff --git a/changelogs/unreleased/fix-udpate-head-pipeline-method.yml b/changelogs/unreleased/fix-udpate-head-pipeline-method.yml new file mode 100644 index 00000000000..8dbb9f8e42b --- /dev/null +++ b/changelogs/unreleased/fix-udpate-head-pipeline-method.yml @@ -0,0 +1,5 @@ +--- +title: Fix unexpected exception by failure of finding an actual head pipeline +merge_request: 24257 +author: +type: fixed diff --git a/spec/models/merge_request_spec.rb b/spec/models/merge_request_spec.rb index 96d49e86dab..ed80a662a3b 100644 --- a/spec/models/merge_request_spec.rb +++ b/spec/models/merge_request_spec.rb @@ -1390,6 +1390,23 @@ describe MergeRequest do .to change { merge_request.reload.head_pipeline } .from(nil).to(pipeline) 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 context 'when there are no pipelines with the diff head sha' do |