Fix import of notes on Pull Request diff

parent 39ab842b
...@@ -30,6 +30,14 @@ module Github ...@@ -30,6 +30,14 @@ module Github
self.reset_callbacks :validate self.reset_callbacks :validate
end end
class LegacyDiffNote < ::LegacyDiffNote
self.table_name = 'notes'
self.reset_callbacks :commit
self.reset_callbacks :update
self.reset_callbacks :validate
end
attr_reader :project, :repository, :repo, :options, :errors, :cached attr_reader :project, :repository, :repo, :options, :errors, :cached
def initialize(project, options) def initialize(project, options)
...@@ -177,7 +185,7 @@ module Github ...@@ -177,7 +185,7 @@ module Github
# Fetch review comments # Fetch review comments
review_comments_url = "/repos/#{repo}/pulls/#{pull_request.iid}/comments" review_comments_url = "/repos/#{repo}/pulls/#{pull_request.iid}/comments"
fetch_comments(merge_request, :review_comment, review_comments_url) fetch_comments(merge_request, :review_comment, review_comments_url, LegacyDiffNote)
# Fetch comments # Fetch comments
comments_url = "/repos/#{repo}/issues/#{pull_request.iid}/comments" comments_url = "/repos/#{repo}/issues/#{pull_request.iid}/comments"
...@@ -245,7 +253,7 @@ module Github ...@@ -245,7 +253,7 @@ module Github
end end
end end
def fetch_comments(noteable, type, url) def fetch_comments(noteable, type, url, klass = Note)
while url while url
comments = Github::Client.new(options).get(url) comments = Github::Client.new(options).get(url)
...@@ -255,14 +263,13 @@ module Github ...@@ -255,14 +263,13 @@ module Github
representation = Github::Representation::Comment.new(raw, options) representation = Github::Representation::Comment.new(raw, options)
author_id = user_id(representation.author, project.creator_id) author_id = user_id(representation.author, project.creator_id)
note = Note.new note = klass.new
note.project_id = project.id note.project_id = project.id
note.noteable = noteable note.noteable = noteable
note.note = format_description(representation.note, representation.author) note.note = format_description(representation.note, representation.author)
note.commit_id = representation.commit_id note.commit_id = representation.commit_id
note.line_code = representation.line_code note.line_code = representation.line_code
note.author_id = author_id note.author_id = author_id
note.type = representation.type
note.created_at = representation.created_at note.created_at = representation.created_at
note.updated_at = representation.updated_at note.updated_at = representation.updated_at
note.save!(validate: false) note.save!(validate: false)
......
...@@ -20,10 +20,6 @@ module Github ...@@ -20,10 +20,6 @@ module Github
generate_line_code(parsed_lines.to_a.last) generate_line_code(parsed_lines.to_a.last)
end end
def type
'LegacyDiffNote' if on_diff?
end
private private
def generate_line_code(line) def generate_line_code(line)
......
...@@ -9,7 +9,7 @@ module Github ...@@ -9,7 +9,7 @@ module Github
end end
def body def body
@body ||= Oj.load(raw.body, class_cache: false, mode: :compat) Oj.load(raw.body, class_cache: false, mode: :compat)
end end
def rels def rels
......
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