Import issues comments

parent c2607666
...@@ -224,6 +224,36 @@ module Github ...@@ -224,6 +224,36 @@ module Github
issue.created_at = representation.created_at issue.created_at = representation.created_at
issue.updated_at = representation.updated_at issue.updated_at = representation.updated_at
issue.save(validate: false) 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 rescue => e
error(:issue, representation.url, e.message) error(:issue, representation.url, e.message)
end end
......
...@@ -49,6 +49,10 @@ module Github ...@@ -49,6 +49,10 @@ module Github
raw['assignee'].present? raw['assignee'].present?
end end
def has_comments?
raw['comments'] > 0
end
def pull_request? def pull_request?
raw['pull_request'].present? raw['pull_request'].present?
end end
......
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