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:
parent
450b9f6e30
commit
e4612df0e2
3 changed files with 19 additions and 1 deletions
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
title: Ensure MR diffs always exist in the PR importer
|
||||
merge_request:
|
||||
author:
|
||||
type: fixed
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue