Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
9490ef6e
Commit
9490ef6e
authored
Feb 28, 2022
by
Doug Stull
Committed by
Luke Duncalfe
Feb 28, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Raise error when diff note import fails
Allow suggestions to still be imported if outdated Changelog: fixed
parent
ee027ef5
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
4 deletions
+26
-4
lib/gitlab/github_import/importer/diff_note_importer.rb
lib/gitlab/github_import/importer/diff_note_importer.rb
+6
-2
spec/lib/gitlab/github_import/importer/diff_note_importer_spec.rb
.../gitlab/github_import/importer/diff_note_importer_spec.rb
+20
-2
No files found.
lib/gitlab/github_import/importer/diff_note_importer.rb
View file @
9490ef6e
...
...
@@ -4,6 +4,8 @@ module Gitlab
module
GithubImport
module
Importer
class
DiffNoteImporter
DiffNoteCreationError
=
Class
.
new
(
ActiveRecord
::
RecordInvalid
)
# note - An instance of `Gitlab::GithubImport::Representation::DiffNote`
# project - An instance of `Project`
# client - An instance of `Gitlab::GithubImport::Client`
...
...
@@ -31,7 +33,7 @@ module Gitlab
else
import_with_legacy_diff_note
end
rescue
::
DiffNote
::
NoteDiffFileCreationError
=>
e
rescue
::
DiffNote
::
NoteDiffFileCreationError
,
DiffNoteCreationError
=>
e
Logger
.
warn
(
message:
e
.
message
,
'error.class'
:
e
.
class
.
name
)
import_with_legacy_diff_note
...
...
@@ -84,7 +86,7 @@ module Gitlab
def
import_with_diff_note
log_diff_note_creation
(
'DiffNote'
)
::
Import
::
Github
::
Notes
::
CreateService
.
new
(
project
,
author
,
{
record
=
::
Import
::
Github
::
Notes
::
CreateService
.
new
(
project
,
author
,
{
noteable_type:
note
.
noteable_type
,
system:
false
,
type:
'DiffNote'
,
...
...
@@ -97,6 +99,8 @@ module Gitlab
updated_at:
note
.
updated_at
,
position:
note
.
diff_position
}).
execute
raise
DiffNoteCreationError
,
record
unless
record
.
persisted?
end
def
note_body
...
...
spec/lib/gitlab/github_import/importer/diff_note_importer_spec.rb
View file @
9490ef6e
...
...
@@ -12,6 +12,7 @@ RSpec.describe Gitlab::GithubImport::Importer::DiffNoteImporter, :aggregate_fail
let
(
:updated_at
)
{
Time
.
new
(
2017
,
1
,
1
,
12
,
15
).
utc
}
let
(
:note_body
)
{
'Hello'
}
let
(
:file_path
)
{
'files/ruby/popen.rb'
}
let
(
:end_line
)
{
15
}
let
(
:diff_hunk
)
do
'@@ -14 +14 @@
...
...
@@ -31,7 +32,7 @@ RSpec.describe Gitlab::GithubImport::Importer::DiffNoteImporter, :aggregate_fail
created_at:
created_at
,
updated_at:
updated_at
,
start_line:
nil
,
end_line:
15
,
end_line:
end_line
,
github_id:
1
,
diff_hunk:
diff_hunk
,
side:
'RIGHT'
...
...
@@ -173,7 +174,24 @@ RSpec.describe Gitlab::GithubImport::Importer::DiffNoteImporter, :aggregate_fail
NOTE
end
context
'when the note diff file creation fails'
do
context
'when the note diff file creation fails with DiffNoteCreationError due to outdated suggestion'
do
let
(
:end_line
)
{
nil
}
it
'falls back to the LegacyDiffNote'
do
expect
(
Gitlab
::
GithubImport
::
Logger
)
.
to
receive
(
:warn
)
.
with
(
message:
"Validation failed: Line code can't be blank, Line code must be a valid line code, Position is incomplete"
,
'error.class'
:
'Gitlab::GithubImport::Importer::DiffNoteImporter::DiffNoteCreationError'
)
expect
{
subject
.
execute
}
.
to
change
(
LegacyDiffNote
,
:count
)
.
and
not_change
(
DiffNote
,
:count
)
end
end
context
'when the note diff file creation fails with NoteDiffFileCreationError'
do
it
'falls back to the LegacyDiffNote'
do
exception
=
::
DiffNote
::
NoteDiffFileCreationError
.
new
(
'Failed to create diff note file'
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment