Commit 44cdc72e authored by Matthias Käppler's avatar Matthias Käppler

Merge branch 'kassio/github-importer-fallback-failed-diffnote-suggestion' into 'master'

GithubImporter: Fallback to LegacyDiffNote when DiffNote fails

See merge request gitlab-org/gitlab!76376
parents ee859d7f 0b8c2bea
...@@ -31,6 +31,10 @@ module Gitlab ...@@ -31,6 +31,10 @@ module Gitlab
else else
import_with_legacy_diff_note import_with_legacy_diff_note
end end
rescue ::DiffNote::NoteDiffFileCreationError => e
Logger.warn(message: e.message, 'error.class': e.class.name)
import_with_legacy_diff_note
rescue ActiveRecord::InvalidForeignKey => e rescue ActiveRecord::InvalidForeignKey => e
# It's possible the project and the issue have been deleted since # It's possible the project and the issue have been deleted since
# scheduling this job. In this case we'll just skip creating the note # scheduling this job. In this case we'll just skip creating the note
......
...@@ -4,6 +4,7 @@ module Gitlab ...@@ -4,6 +4,7 @@ module Gitlab
module GithubImport module GithubImport
module Representation module Representation
class DiffNote class DiffNote
include Gitlab::Utils::StrongMemoize
include ToHash include ToHash
include ExposeAttribute include ExposeAttribute
...@@ -127,15 +128,17 @@ module Gitlab ...@@ -127,15 +128,17 @@ module Gitlab
end end
def discussion_id def discussion_id
if in_reply_to_id.present? strong_memoize(:discussion_id) do
current_discussion_id if in_reply_to_id.present?
else current_discussion_id
Discussion.discussion_id( else
Struct Discussion.discussion_id(
.new(:noteable_id, :noteable_type) Struct
.new(merge_request.id, NOTEABLE_TYPE) .new(:noteable_id, :noteable_type)
).tap do |discussion_id| .new(merge_request.id, NOTEABLE_TYPE)
cache_discussion_id(discussion_id) ).tap do |discussion_id|
cache_discussion_id(discussion_id)
end
end end
end end
end end
......
...@@ -173,9 +173,11 @@ RSpec.describe Gitlab::GithubImport::Importer::DiffNoteImporter, :aggregate_fail ...@@ -173,9 +173,11 @@ RSpec.describe Gitlab::GithubImport::Importer::DiffNoteImporter, :aggregate_fail
EOB EOB
end end
it 'imports the note as diff note' do before do
stub_user_finder(user.id, true) stub_user_finder(user.id, true)
end
it 'imports the note as diff note' do
expect { subject.execute } expect { subject.execute }
.to change(DiffNote, :count) .to change(DiffNote, :count)
.by(1) .by(1)
...@@ -212,6 +214,29 @@ RSpec.describe Gitlab::GithubImport::Importer::DiffNoteImporter, :aggregate_fail ...@@ -212,6 +214,29 @@ RSpec.describe Gitlab::GithubImport::Importer::DiffNoteImporter, :aggregate_fail
``` ```
NOTE NOTE
end end
context 'when the note diff file creation fails' do
it 'falls back to the LegacyDiffNote' do
exception = ::DiffNote::NoteDiffFileCreationError.new('Failed to create diff note file')
expect_next_instance_of(::Import::Github::Notes::CreateService) do |service|
expect(service)
.to receive(:execute)
.and_raise(exception)
end
expect(Gitlab::GithubImport::Logger)
.to receive(:warn)
.with(
message: 'Failed to create diff note file',
'error.class': 'DiffNote::NoteDiffFileCreationError'
)
expect { subject.execute }
.to change(LegacyDiffNote, :count)
.and not_change(DiffNote, :count)
end
end
end end
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