From db3220092ade9cb604b24e56a2c21092d8708f9c Mon Sep 17 00:00:00 2001 From: Douglas Barbosa Alexandre Date: Thu, 13 Apr 2017 17:31:29 -0300 Subject: Import issues comments --- lib/github/import.rb | 30 ++++++++++++++++++++++++++++++ lib/github/representation/issue.rb | 4 ++++ 2 files changed, 34 insertions(+) diff --git a/lib/github/import.rb b/lib/github/import.rb index c4b03da9bc1..c1596e97b3a 100644 --- a/lib/github/import.rb +++ b/lib/github/import.rb @@ -224,6 +224,36 @@ module Github issue.created_at = representation.created_at issue.updated_at = representation.updated_at issue.save(validate: false) + + if issue.has_comments? + # Fetch comments + comments_url = "/repos/#{owner}/#{repo}/issues/#{issue.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 = issue + 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 + end rescue => e error(:issue, representation.url, e.message) end diff --git a/lib/github/representation/issue.rb b/lib/github/representation/issue.rb index 62c71cc191b..c73eefa0983 100644 --- a/lib/github/representation/issue.rb +++ b/lib/github/representation/issue.rb @@ -49,6 +49,10 @@ module Github raw['assignee'].present? end + def has_comments? + raw['comments'] > 0 + end + def pull_request? raw['pull_request'].present? end -- cgit v1.2.1