From c26076664f557f697555ced7e97fff9ea8f88aab Mon Sep 17 00:00:00 2001 From: Douglas Barbosa Alexandre Date: Thu, 13 Apr 2017 17:05:39 -0300 Subject: Import pull requests comments --- lib/github/import.rb | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 61 insertions(+), 1 deletion(-) (limited to 'lib/github') diff --git a/lib/github/import.rb b/lib/github/import.rb index 19d366b0444..c4b03da9bc1 100644 --- a/lib/github/import.rb +++ b/lib/github/import.rb @@ -126,9 +126,69 @@ module Github merge_request.assignee_id = user_id(pull_request.assignee) merge_request.created_at = pull_request.created_at merge_request.updated_at = pull_request.updated_at - merge_request.save(validate: false) + merge_request.save!(validate: false) merge_request.merge_request_diffs.create + + # Fetch review comments + review_comments_url = "/repos/#{owner}/#{repo}/pulls/#{pull_request.iid}/comments" + + loop do + review_comments = Github::Client.new.get(review_comments_url) + + ActiveRecord::Base.no_touching do + review_comments.body.each do |raw| + begin + comment = Github::Representation::Comment.new(raw) + + note = Note.new + note.project_id = project.id + note.noteable = merge_request + note.note = comment.note + note.commit_id = comment.commit_id + note.line_code = comment.line_code + note.author_id = user_id(comment.author, project.creator_id) + note.type = comment.type + note.created_at = comment.created_at + note.updated_at = comment.updated_at + note.save!(validate: false) + rescue => e + error(:review_comment, comment.url, e.message) + end + end + end + + break unless review_comments_url = review_comments.rels[:next] + end + + # Fetch comments + comments_url = "/repos/#{owner}/#{repo}/issues/#{pull_request.iid}/comments" + + loop do + comments = Github::Client.new.get(comments_url) + + ActiveRecord::Base.no_touching do + comments.body.each do |raw| + begin + comment = Github::Representation::Comment.new(raw) + + note = Note.new + note.project_id = project.id + note.noteable = merge_request + note.note = comment.note + note.author_id = user_id(comment.author, project.creator_id) + note.created_at = comment.created_at + note.updated_at = comment.updated_at + note.save!(validate: false) + rescue => e + error(:comment, comment.url, e.message) + end + end + end + + break unless comments_url = comments.rels[:next] + end + rescue => e error(:pull_request, pull_request.url, e.message) ensure -- cgit v1.2.1