Commit 0b8c2bea authored by Kassio Borges's avatar Kassio Borges

GithubImporter: Fallback to LegacyDiffNote when DiffNote fails

When `DiffNote` fails to create the diff note file with
`DiffNote::NoteDiffFileCreationError` exception, fallsback to use the
`LegacyDiffNote`.

Changelog: fixed
parent 1ef5119b
......@@ -31,6 +31,10 @@ module Gitlab
else
import_with_legacy_diff_note
end
rescue ::DiffNote::NoteDiffFileCreationError => e
Logger.warn(message: e.message, 'error.class': e.class.name)
import_with_legacy_diff_note
rescue ActiveRecord::InvalidForeignKey => e
# 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
......
......@@ -4,6 +4,7 @@ module Gitlab
module GithubImport
module Representation
class DiffNote
include Gitlab::Utils::StrongMemoize
include ToHash
include ExposeAttribute
......@@ -127,6 +128,7 @@ module Gitlab
end
def discussion_id
strong_memoize(:discussion_id) do
if in_reply_to_id.present?
current_discussion_id
else
......@@ -139,6 +141,7 @@ module Gitlab
end
end
end
end
private
......
......@@ -173,9 +173,11 @@ RSpec.describe Gitlab::GithubImport::Importer::DiffNoteImporter, :aggregate_fail
EOB
end
it 'imports the note as diff note' do
before do
stub_user_finder(user.id, true)
end
it 'imports the note as diff note' do
expect { subject.execute }
.to change(DiffNote, :count)
.by(1)
......@@ -212,6 +214,29 @@ RSpec.describe Gitlab::GithubImport::Importer::DiffNoteImporter, :aggregate_fail
```
NOTE
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
......
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