Commit e4612df0 authored by Yorick Peterse's avatar Yorick Peterse

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.
parent 450b9f6e
---
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
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