Commit bc2f2482 authored by George Koltsov's avatar George Koltsov

Fix GitHub Importer outdated diff notes not showing

  - Update diff notes coming from GitHub to include
    original_commit_id instead of commit_id as well
    as add discussion_id to fix display of these
    notes in the UI

Changelog: fixed
parent 00a771a3
...@@ -24,13 +24,14 @@ module Gitlab ...@@ -24,13 +24,14 @@ module Gitlab
note_body = MarkdownText.format(note.note, note.author, author_found) note_body = MarkdownText.format(note.note, note.author, author_found)
attributes = { attributes = {
discussion_id: Discussion.discussion_id(note),
noteable_type: 'MergeRequest', noteable_type: 'MergeRequest',
noteable_id: mr_id, noteable_id: mr_id,
project_id: project.id, project_id: project.id,
author_id: author_id, author_id: author_id,
note: note_body, note: note_body,
system: false, system: false,
commit_id: note.commit_id, commit_id: note.original_commit_id,
line_code: note.line_code, line_code: note.line_code,
type: 'LegacyDiffNote', type: 'LegacyDiffNote',
created_at: note.created_at, created_at: note.created_at,
......
...@@ -11,7 +11,7 @@ module Gitlab ...@@ -11,7 +11,7 @@ module Gitlab
expose_attribute :noteable_type, :noteable_id, :commit_id, :file_path, expose_attribute :noteable_type, :noteable_id, :commit_id, :file_path,
:diff_hunk, :author, :note, :created_at, :updated_at, :diff_hunk, :author, :note, :created_at, :updated_at,
:github_id :github_id, :original_commit_id
NOTEABLE_ID_REGEX = %r{/pull/(?<iid>\d+)}i.freeze NOTEABLE_ID_REGEX = %r{/pull/(?<iid>\d+)}i.freeze
...@@ -34,6 +34,7 @@ module Gitlab ...@@ -34,6 +34,7 @@ module Gitlab
noteable_id: matches[:iid].to_i, noteable_id: matches[:iid].to_i,
file_path: note.path, file_path: note.path,
commit_id: note.commit_id, commit_id: note.commit_id,
original_commit_id: note.original_commit_id,
diff_hunk: note.diff_hunk, diff_hunk: note.diff_hunk,
author: user, author: user,
note: note.body, note: note.body,
......
...@@ -20,6 +20,7 @@ RSpec.describe Gitlab::GithubImport::Importer::DiffNoteImporter do ...@@ -20,6 +20,7 @@ RSpec.describe Gitlab::GithubImport::Importer::DiffNoteImporter do
noteable_type: 'MergeRequest', noteable_type: 'MergeRequest',
noteable_id: 1, noteable_id: 1,
commit_id: '123abc', commit_id: '123abc',
original_commit_id: 'original123abc',
file_path: 'README.md', file_path: 'README.md',
diff_hunk: hunk, diff_hunk: hunk,
author: Gitlab::GithubImport::Representation::User author: Gitlab::GithubImport::Representation::User
...@@ -64,13 +65,14 @@ RSpec.describe Gitlab::GithubImport::Importer::DiffNoteImporter do ...@@ -64,13 +65,14 @@ RSpec.describe Gitlab::GithubImport::Importer::DiffNoteImporter do
LegacyDiffNote.table_name, LegacyDiffNote.table_name,
[ [
{ {
discussion_id: anything,
noteable_type: 'MergeRequest', noteable_type: 'MergeRequest',
noteable_id: merge_request.id, noteable_id: merge_request.id,
project_id: project.id, project_id: project.id,
author_id: user.id, author_id: user.id,
note: 'Hello', note: 'Hello',
system: false, system: false,
commit_id: '123abc', commit_id: 'original123abc',
line_code: note.line_code, line_code: note.line_code,
type: 'LegacyDiffNote', type: 'LegacyDiffNote',
created_at: created_at, created_at: created_at,
...@@ -95,13 +97,14 @@ RSpec.describe Gitlab::GithubImport::Importer::DiffNoteImporter do ...@@ -95,13 +97,14 @@ RSpec.describe Gitlab::GithubImport::Importer::DiffNoteImporter do
LegacyDiffNote.table_name, LegacyDiffNote.table_name,
[ [
{ {
discussion_id: anything,
noteable_type: 'MergeRequest', noteable_type: 'MergeRequest',
noteable_id: merge_request.id, noteable_id: merge_request.id,
project_id: project.id, project_id: project.id,
author_id: project.creator_id, author_id: project.creator_id,
note: "*Created by: #{user.username}*\n\nHello", note: "*Created by: #{user.username}*\n\nHello",
system: false, system: false,
commit_id: '123abc', commit_id: 'original123abc',
line_code: note.line_code, line_code: note.line_code,
type: 'LegacyDiffNote', type: 'LegacyDiffNote',
created_at: created_at, created_at: created_at,
......
...@@ -12,6 +12,7 @@ RSpec.describe Gitlab::GithubImport::Importer::DiffNotesImporter do ...@@ -12,6 +12,7 @@ RSpec.describe Gitlab::GithubImport::Importer::DiffNotesImporter do
html_url: 'https://github.com/foo/bar/pull/42', html_url: 'https://github.com/foo/bar/pull/42',
path: 'README.md', path: 'README.md',
commit_id: '123abc', commit_id: '123abc',
original_commit_id: 'original123abc',
diff_hunk: "@@ -1 +1 @@\n-Hello\n+Hello world", diff_hunk: "@@ -1 +1 @@\n-Hello\n+Hello world",
user: double(:user, id: 4, login: 'alice'), user: double(:user, id: 4, login: 'alice'),
body: 'Hello world', body: 'Hello world',
......
...@@ -67,6 +67,7 @@ RSpec.describe Gitlab::GithubImport::Representation::DiffNote do ...@@ -67,6 +67,7 @@ RSpec.describe Gitlab::GithubImport::Representation::DiffNote do
html_url: 'https://github.com/foo/bar/pull/42', html_url: 'https://github.com/foo/bar/pull/42',
path: 'README.md', path: 'README.md',
commit_id: '123abc', commit_id: '123abc',
original_commit_id: 'original123abc',
diff_hunk: hunk, diff_hunk: hunk,
user: double(:user, id: 4, login: 'alice'), user: double(:user, id: 4, login: 'alice'),
body: 'Hello world', body: 'Hello world',
...@@ -99,6 +100,7 @@ RSpec.describe Gitlab::GithubImport::Representation::DiffNote do ...@@ -99,6 +100,7 @@ RSpec.describe Gitlab::GithubImport::Representation::DiffNote do
'noteable_id' => 42, 'noteable_id' => 42,
'file_path' => 'README.md', 'file_path' => 'README.md',
'commit_id' => '123abc', 'commit_id' => '123abc',
'original_commit_id' => 'original123abc',
'diff_hunk' => hunk, 'diff_hunk' => hunk,
'author' => { 'id' => 4, 'login' => 'alice' }, 'author' => { 'id' => 4, 'login' => 'alice' },
'note' => 'Hello world', 'note' => 'Hello world',
...@@ -117,6 +119,7 @@ RSpec.describe Gitlab::GithubImport::Representation::DiffNote do ...@@ -117,6 +119,7 @@ RSpec.describe Gitlab::GithubImport::Representation::DiffNote do
'noteable_id' => 42, 'noteable_id' => 42,
'file_path' => 'README.md', 'file_path' => 'README.md',
'commit_id' => '123abc', 'commit_id' => '123abc',
'original_commit_id' => 'original123abc',
'diff_hunk' => hunk, 'diff_hunk' => hunk,
'note' => 'Hello world', 'note' => 'Hello world',
'created_at' => created_at.to_s, 'created_at' => created_at.to_s,
...@@ -145,6 +148,7 @@ RSpec.describe Gitlab::GithubImport::Representation::DiffNote do ...@@ -145,6 +148,7 @@ RSpec.describe Gitlab::GithubImport::Representation::DiffNote do
'noteable_id' => 42, 'noteable_id' => 42,
'file_path' => 'README.md', 'file_path' => 'README.md',
'commit_id' => '123abc', 'commit_id' => '123abc',
'original_commit_id' => 'original123abc',
'diff_hunk' => hunk, 'diff_hunk' => hunk,
'author' => { 'id' => 4, 'login' => 'alice' }, 'author' => { 'id' => 4, 'login' => 'alice' },
'note' => 'Hello world', 'note' => 'Hello world',
......
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