Commit ec512406 authored by George Koltsov's avatar George Koltsov

Add commit_id to AttributeCleaner::ALLOWED_REFERENCES

parent ebed862a
...@@ -588,9 +588,11 @@ class MergeRequest < ApplicationRecord ...@@ -588,9 +588,11 @@ class MergeRequest < ApplicationRecord
end end
def diff_refs def diff_refs
return merge_request_diff.diff_refs if importing? if importing? || persisted?
merge_request_diff.diff_refs
persisted? ? merge_request_diff.diff_refs : repository_diff_refs else
repository_diff_refs
end
end end
# Instead trying to fetch the # Instead trying to fetch the
......
--- ---
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 merge_request: 30630
author: author:
type: fixed type: fixed
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
module Gitlab module Gitlab
module ImportExport module ImportExport
class AttributeCleaner 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 PROHIBITED_REFERENCES = Regexp.union(/\Acached_markdown_version\Z/, /_id\Z/, /_html\Z/).freeze
def self.clean(*args) def self.clean(*args)
......
...@@ -22,7 +22,9 @@ describe Gitlab::ImportExport::AttributeCleaner do ...@@ -22,7 +22,9 @@ describe Gitlab::ImportExport::AttributeCleaner do
'some_html' => '<p>dodgy html</p>', 'some_html' => '<p>dodgy html</p>',
'legit_html' => '<p>legit html</p>', 'legit_html' => '<p>legit html</p>',
'_html' => '<p>perfectly ordinary html</p>', '_html' => '<p>perfectly ordinary html</p>',
'cached_markdown_version' => 12345 'cached_markdown_version' => 12345,
'group_id' => 99,
'commit_id' => 99
} }
end end
...@@ -31,7 +33,9 @@ describe Gitlab::ImportExport::AttributeCleaner do ...@@ -31,7 +33,9 @@ describe Gitlab::ImportExport::AttributeCleaner do
'project_id' => 99, 'project_id' => 99,
'user_id' => 99, 'user_id' => 99,
'random_id_in_the_middle' => 99, 'random_id_in_the_middle' => 99,
'notid' => 99 'notid' => 99,
'group_id' => 99,
'commit_id' => 99
} }
end end
...@@ -59,6 +63,6 @@ describe Gitlab::ImportExport::AttributeCleaner do ...@@ -59,6 +63,6 @@ describe Gitlab::ImportExport::AttributeCleaner do
it 'does not remove excluded key if not listed' do it 'does not remove excluded key if not listed' do
parsed_hash = described_class.clean(relation_hash: unsafe_hash, relation_class: relation_class) 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
end end
...@@ -2454,13 +2454,13 @@ describe MergeRequest do ...@@ -2454,13 +2454,13 @@ describe MergeRequest do
describe "#diff_refs" do describe "#diff_refs" do
context "with diffs" do context "with diffs" do
subject { create(:merge_request, :with_diffs) } subject { create(:merge_request, :with_diffs) }
let(:expected_diff_refs) { let(:expected_diff_refs) do
Gitlab::Diff::DiffRefs.new( Gitlab::Diff::DiffRefs.new(
base_sha: subject.merge_request_diff.base_commit_sha, base_sha: subject.merge_request_diff.base_commit_sha,
start_sha: subject.merge_request_diff.start_commit_sha, start_sha: subject.merge_request_diff.start_commit_sha,
head_sha: subject.merge_request_diff.head_commit_sha head_sha: subject.merge_request_diff.head_commit_sha
) )
} end
it "does not touch the repository" do it "does not touch the repository" do
subject # Instantiate the object subject # Instantiate the object
......
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