Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/ghtorrent/api_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ module APIClient
# A paged request. Used when the result can expand to more than one
# result pages.
def paged_api_request(url, pages = config(:mirror_history_pages_back),
last = nil)
last = nil, media_type = '')

url = ensure_max_per_page(url)
data = api_request_raw(url)
data = api_request_raw(url, media_type)

return [] if data.nil?

Expand All @@ -39,7 +39,7 @@ def paged_api_request(url, pages = config(:mirror_history_pages_back),
if links['next'].nil?
parse_request_result(data)
else
parse_request_result(data) | paged_api_request(links['next'], pages, last)
parse_request_result(data) | paged_api_request(links['next'], pages, last, media_type)
end
else
parse_request_result(data)
Expand Down
2 changes: 1 addition & 1 deletion lib/ghtorrent/commands/full_repo_retriever.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def retrieve_full_repo(owner, repo)
send(event['type'], event)
info "Success processing event. Type: #{event['type']}, ID: #{event['id']}"
rescue StandardError => e
warn "Error processing event. Type: #{event['type']}, ID: #{event['id']}"
warn "Error processing event. Type: #{event['type']}, ID: #{event['id']}.\nError: #{$!}\n#{e.backtrace.join("\n")}."
end
end
end
Expand Down
43 changes: 35 additions & 8 deletions lib/ghtorrent/ghtorrent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1662,29 +1662,56 @@ def ensure_issue_comment(owner, repo, issue_id, comment_id, pull_req_id = nil)

curcomment = db[:issue_comments].first(:issue_id => issue[:id],
:comment_id => comment_id)
if curcomment.nil?
retrieved = retrieve_issue_comment(owner, repo, issue_id, comment_id)

retrieved = retrieve_issue_comment(owner, repo, issue_id, comment_id)
if retrieved.nil?
warn "Could not retrieve issue_comment #{issue_comment_str}"
return
end

if retrieved.nil?
warn "Could not retrieve issue_comment #{issue_comment_str}"
return
end
reactions = retrieved['reactions']

if curcomment.nil?
user = ensure_user(retrieved['user']['login'], false, false)
reactions = retrieved['reactions']

db[:issue_comments].insert(
:comment_id => comment_id,
:issue_id => issue[:id],
:user_id => unless user.nil? then user[:id] end,
:created_at => date(retrieved['created_at'])
:created_at => date(retrieved['created_at']),
:like => reactions['+1'],
:dislike => reactions['-1'],
:laugh => reactions['laugh'],
:confused => reactions['confused'],
:heart => reactions['heart'],
:hooray => reactions['hooray']
)

info "Added issue_comment #{issue_comment_str}"
db[:issue_comments].first(:issue_id => issue[:id],
:comment_id => comment_id)
else
debug "Issue comment #{issue_comment_str} exists"
if ! (curcomment[:like] == reactions['+1']) or
! (curcomment[:dislike] == reactions['-1']) or
! (curcomment[:laugh] == reactions['laugh']) or
! (curcomment[:confused] == reactions['confused']) or
! (curcomment[:heart] == reactions['heart']) or
! (curcomment[:hooray] == reactions['hooray'])
info "Updating issue comment reactions..."

retrieved = retrieve_issue_comment(owner, repo, issue_id, comment_id)
reactions = retrieved['reactions']
db[:issue_comments].filter(:issue_id => issue[:id],
:comment_id => comment_id).update(:like => reactions['+1'],
:dislike => reactions['-1'],
:laugh => reactions['laugh'],
:confused => reactions['confused'],
:heart => reactions['heart'],
:hooray => reactions['hooray'])
else
info "Comment reactions current"
end
curcomment
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/ghtorrent/migrations/011_add_issues.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,4 @@
drop_table :issue_events
drop_table :issues
end
end
end
27 changes: 27 additions & 0 deletions lib/ghtorrent/migrations/030_add_issue_comment_reactions.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
require 'sequel'

require 'ghtorrent/migrations/mysql_defaults'

Sequel.migration do
up do
puts 'Adding reaction columns to issue_comments'
alter_table :issue_comments do
add_column :like, Integer
add_column :dislike, Integer
add_column :laugh, Integer
add_column :confused, Integer
add_column :heart, Integer
add_column :hooray, Integer
end
end

down do
puts 'Dropping reaction columns from issue_comments'
drop_column :like
drop_column :dislike
drop_column :laugh
drop_column :confused
drop_column :heart
drop_column :hooray
end
end
7 changes: 5 additions & 2 deletions lib/ghtorrent/retriever.rb
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,9 @@ def retrieve_issue_event(owner, repo, issue_id, event_id)

def retrieve_issue_comments(owner, repo, issue_id)
url = ghurl "repos/#{owner}/#{repo}/issues/#{issue_id}/comments"
retrieved_comments = paged_api_request url

retrieved_comments = paged_api_request(url, config(:mirror_history_pages_back),
nil, 'application/vnd.github.squirrel-girl-preview')

comments = retrieved_comments.each { |x|
x['owner'] = owner
Expand All @@ -522,7 +524,8 @@ def retrieve_issue_comment(owner, repo, issue_id, comment_id)
'issue_id' => issue_id,
'id' => comment_id}).first
if comment.nil?
r = api_request(ghurl "repos/#{owner}/#{repo}/issues/comments/#{comment_id}")
r = api_request(ghurl("repos/#{owner}/#{repo}/issues/comments/#{comment_id}"),
media_type = 'application/vnd.github.squirrel-girl-preview') # volatile: https://developer.github.com/v3/issues/comments/#reactions-summary

if r.nil? or r.empty?
warn "Could not find issue_comment #{owner}/#{repo} #{issue_id}->#{comment_id}. Deleted?"
Expand Down