summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Koltsov <gkoltsov@gitlab.com>2019-07-12 10:05:55 +0100
committerGeorge Koltsov <gkoltsov@gitlab.com>2019-07-15 10:30:39 +0100
commitec512406857aecabc577b3fc70ec321982dd65a8 (patch)
tree6e63826c8b4129e0a19ddca879a018689d763996
parentebed862a78c5561bb497fefa041172b4c7440c45 (diff)
downloadgitlab-ce-georgekoltsov/63955-fix-import-with-source-branch-deleted.tar.gz
Add commit_id to AttributeCleaner::ALLOWED_REFERENCESgeorgekoltsov/63955-fix-import-with-source-branch-deleted
-rw-r--r--app/models/merge_request.rb8
-rw-r--r--changelogs/unreleased/georgekoltsov-63955-fix-import-with-source-branch-deleted.yml2
-rw-r--r--lib/gitlab/import_export/attribute_cleaner.rb2
-rw-r--r--spec/lib/gitlab/import_export/attribute_cleaner_spec.rb10
-rw-r--r--spec/models/merge_request_spec.rb4
5 files changed, 16 insertions, 10 deletions
diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb
index 6e9b2ae5867..ba57fefd8f1 100644
--- a/app/models/merge_request.rb
+++ b/app/models/merge_request.rb
@@ -588,9 +588,11 @@ class MergeRequest < ApplicationRecord
end
def diff_refs
- return merge_request_diff.diff_refs if importing?
-
- persisted? ? merge_request_diff.diff_refs : repository_diff_refs
+ if importing? || persisted?
+ merge_request_diff.diff_refs
+ else
+ repository_diff_refs
+ end
end
# Instead trying to fetch the
diff --git a/changelogs/unreleased/georgekoltsov-63955-fix-import-with-source-branch-deleted.yml b/changelogs/unreleased/georgekoltsov-63955-fix-import-with-source-branch-deleted.yml
index 7c13d5d0a46..72e2621c52a 100644
--- a/changelogs/unreleased/georgekoltsov-63955-fix-import-with-source-branch-deleted.yml
+++ b/changelogs/unreleased/georgekoltsov-63955-fix-import-with-source-branch-deleted.yml
@@ -1,5 +1,5 @@
---
-title: Always return MR diff_refs if importing
+title: Fix a bug that prevented projects containing merge request diff comments from being imported
merge_request: 30630
author:
type: fixed
diff --git a/lib/gitlab/import_export/attribute_cleaner.rb b/lib/gitlab/import_export/attribute_cleaner.rb
index c28a1674018..b2fe9592c06 100644
--- a/lib/gitlab/import_export/attribute_cleaner.rb
+++ b/lib/gitlab/import_export/attribute_cleaner.rb
@@ -3,7 +3,7 @@
module Gitlab
module ImportExport
class AttributeCleaner
- ALLOWED_REFERENCES = RelationFactory::PROJECT_REFERENCES + RelationFactory::USER_REFERENCES + ['group_id']
+ ALLOWED_REFERENCES = RelationFactory::PROJECT_REFERENCES + RelationFactory::USER_REFERENCES + %w[group_id commit_id]
PROHIBITED_REFERENCES = Regexp.union(/\Acached_markdown_version\Z/, /_id\Z/, /_html\Z/).freeze
def self.clean(*args)
diff --git a/spec/lib/gitlab/import_export/attribute_cleaner_spec.rb b/spec/lib/gitlab/import_export/attribute_cleaner_spec.rb
index 99669285d5b..873728f9909 100644
--- a/spec/lib/gitlab/import_export/attribute_cleaner_spec.rb
+++ b/spec/lib/gitlab/import_export/attribute_cleaner_spec.rb
@@ -22,7 +22,9 @@ describe Gitlab::ImportExport::AttributeCleaner do
'some_html' => '<p>dodgy html</p>',
'legit_html' => '<p>legit html</p>',
'_html' => '<p>perfectly ordinary html</p>',
- 'cached_markdown_version' => 12345
+ 'cached_markdown_version' => 12345,
+ 'group_id' => 99,
+ 'commit_id' => 99
}
end
@@ -31,7 +33,9 @@ describe Gitlab::ImportExport::AttributeCleaner do
'project_id' => 99,
'user_id' => 99,
'random_id_in_the_middle' => 99,
- 'notid' => 99
+ 'notid' => 99,
+ 'group_id' => 99,
+ 'commit_id' => 99
}
end
@@ -59,6 +63,6 @@ describe Gitlab::ImportExport::AttributeCleaner do
it 'does not remove excluded key if not listed' do
parsed_hash = described_class.clean(relation_hash: unsafe_hash, relation_class: relation_class)
- expect(parsed_hash.keys).to eq post_safe_hash.keys + excluded_keys
+ expect(parsed_hash.keys).to match_array post_safe_hash.keys + excluded_keys
end
end
diff --git a/spec/models/merge_request_spec.rb b/spec/models/merge_request_spec.rb
index 998765325ec..6a5bd276233 100644
--- a/spec/models/merge_request_spec.rb
+++ b/spec/models/merge_request_spec.rb
@@ -2454,13 +2454,13 @@ describe MergeRequest do
describe "#diff_refs" do
context "with diffs" do
subject { create(:merge_request, :with_diffs) }
- let(:expected_diff_refs) {
+ let(:expected_diff_refs) do
Gitlab::Diff::DiffRefs.new(
base_sha: subject.merge_request_diff.base_commit_sha,
start_sha: subject.merge_request_diff.start_commit_sha,
head_sha: subject.merge_request_diff.head_commit_sha
)
- }
+ end
it "does not touch the repository" do
subject # Instantiate the object