diff options
author | Douglas Barbosa Alexandre <dbalexandre@gmail.com> | 2017-04-13 17:31:29 -0300 |
---|---|---|
committer | Douglas Barbosa Alexandre <dbalexandre@gmail.com> | 2017-04-24 16:17:52 -0300 |
commit | db3220092ade9cb604b24e56a2c21092d8708f9c (patch) | |
tree | a77d36a0e61b40e74e6204a118e5119806c38be0 | |
parent | c26076664f557f697555ced7e97fff9ea8f88aab (diff) | |
download | gitlab-ce-db3220092ade9cb604b24e56a2c21092d8708f9c.tar.gz |
Import issues comments
-rw-r--r-- | lib/github/import.rb | 30 | ||||
-rw-r--r-- | lib/github/representation/issue.rb | 4 |
2 files changed, 34 insertions, 0 deletions
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 |