Ensure MR diffs always exist in the PR importer

In rare cases it could happen that an MR was created, but creating the
MR diffs somehow failed (e.g. due to an error). This commit adds an
additional check to make sure MR diffs are always present when importing
GitHub pull requests.
This commit is contained in:
Yorick Peterse 2018-06-12 13:29:43 +02:00
parent 450b9f6e30
commit e4612df0e2
No known key found for this signature in database
GPG key ID: EDD30D2BEB691AC9
3 changed files with 19 additions and 1 deletions

View file

@ -0,0 +1,5 @@
---
title: Ensure MR diffs always exist in the PR importer
merge_request:
author:
type: fixed

View file

@ -104,7 +104,8 @@ module Gitlab
# first save the diff, then populate it.
diff =
if already_exists
merge_request.merge_request_diffs.take
merge_request.merge_request_diffs.take ||
merge_request.merge_request_diffs.build
else
merge_request.merge_request_diffs.build
end

View file

@ -276,5 +276,17 @@ describe Gitlab::GithubImport::Importer::PullRequestImporter, :clean_gitlab_redi
expect(diff.merge_request_diff_commits.exists?).to eq(true)
end
context 'when the merge request exists' do
it 'creates the merge request diffs if they do not yet exist' do
mr, _ = importer.create_merge_request
mr.merge_request_diffs.delete_all
importer.insert_git_data(mr, true)
expect(mr.merge_request_diffs.exists?).to eq(true)
end
end
end
end