summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Thomas <nick@gitlab.com>2018-06-12 14:08:51 +0000
committerNick Thomas <nick@gitlab.com>2018-06-12 14:08:51 +0000
commit893c824ed3f99d5c1f79f09acb12eac5ce5e159f (patch)
tree05a8520e7a805b7f7720cc7dd1a7ee8c9af1335a
parent8b0d2283d77df0e99f5f49db3f78f6101ac1b8ef (diff)
parente4612df0e257a27b47986a9ee6aa77f68a9cd3ba (diff)
downloadgitlab-ce-893c824ed3f99d5c1f79f09acb12eac5ce5e159f.tar.gz
Merge branch 'pr-importer-io-extra-error-handling' into 'master'
Ensure MR diffs always exist in the PR importer Closes #47312 See merge request gitlab-org/gitlab-ce!19704
-rw-r--r--changelogs/unreleased/pr-importer-io-extra-error-handling.yml5
-rw-r--r--lib/gitlab/github_import/importer/pull_request_importer.rb3
-rw-r--r--spec/lib/gitlab/github_import/importer/pull_request_importer_spec.rb12
3 files changed, 19 insertions, 1 deletions
diff --git a/changelogs/unreleased/pr-importer-io-extra-error-handling.yml b/changelogs/unreleased/pr-importer-io-extra-error-handling.yml
new file mode 100644
index 00000000000..2f7121b2840
--- /dev/null
+++ b/changelogs/unreleased/pr-importer-io-extra-error-handling.yml
@@ -0,0 +1,5 @@
+---
+title: Ensure MR diffs always exist in the PR importer
+merge_request:
+author:
+type: fixed
diff --git a/lib/gitlab/github_import/importer/pull_request_importer.rb b/lib/gitlab/github_import/importer/pull_request_importer.rb
index b2f6cb7ad19..6b3688c4381 100644
--- a/lib/gitlab/github_import/importer/pull_request_importer.rb
+++ b/lib/gitlab/github_import/importer/pull_request_importer.rb
@@ -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
diff --git a/spec/lib/gitlab/github_import/importer/pull_request_importer_spec.rb b/spec/lib/gitlab/github_import/importer/pull_request_importer_spec.rb
index 6686b7ce0b5..3422a1e82fc 100644
--- a/spec/lib/gitlab/github_import/importer/pull_request_importer_spec.rb
+++ b/spec/lib/gitlab/github_import/importer/pull_request_importer_spec.rb
@@ -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