summaryrefslogtreecommitdiff
path: root/lib/github
diff options
context:
space:
mode:
authorDouglas Barbosa Alexandre <dbalexandre@gmail.com>2017-04-13 17:05:39 -0300
committerDouglas Barbosa Alexandre <dbalexandre@gmail.com>2017-04-24 16:17:52 -0300
commitc26076664f557f697555ced7e97fff9ea8f88aab (patch)
tree436594a73b9ce1ab8c3abc8f15a9282e75dfc8aa /lib/github
parenteb95f0e5b2bc606eeffb2e214379082862d973d6 (diff)
downloadgitlab-ce-c26076664f557f697555ced7e97fff9ea8f88aab.tar.gz
Import pull requests comments
Diffstat (limited to 'lib/github')
-rw-r--r--lib/github/import.rb62
1 files changed, 61 insertions, 1 deletions
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