diff --git a/lib/ghtorrent/api_client.rb b/lib/ghtorrent/api_client.rb index b64991e..a399d17 100644 --- a/lib/ghtorrent/api_client.rb +++ b/lib/ghtorrent/api_client.rb @@ -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? @@ -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) diff --git a/lib/ghtorrent/commands/full_repo_retriever.rb b/lib/ghtorrent/commands/full_repo_retriever.rb index 4e6ba58..2f5cf38 100644 --- a/lib/ghtorrent/commands/full_repo_retriever.rb +++ b/lib/ghtorrent/commands/full_repo_retriever.rb @@ -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 diff --git a/lib/ghtorrent/ghtorrent.rb b/lib/ghtorrent/ghtorrent.rb index 81d3181..19fca5a 100644 --- a/lib/ghtorrent/ghtorrent.rb +++ b/lib/ghtorrent/ghtorrent.rb @@ -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 diff --git a/lib/ghtorrent/migrations/011_add_issues.rb b/lib/ghtorrent/migrations/011_add_issues.rb index 29166b8..258492b 100644 --- a/lib/ghtorrent/migrations/011_add_issues.rb +++ b/lib/ghtorrent/migrations/011_add_issues.rb @@ -70,4 +70,4 @@ drop_table :issue_events drop_table :issues end -end \ No newline at end of file +end diff --git a/lib/ghtorrent/migrations/030_add_issue_comment_reactions.rb b/lib/ghtorrent/migrations/030_add_issue_comment_reactions.rb new file mode 100644 index 0000000..7d71605 --- /dev/null +++ b/lib/ghtorrent/migrations/030_add_issue_comment_reactions.rb @@ -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 diff --git a/lib/ghtorrent/retriever.rb b/lib/ghtorrent/retriever.rb index b3032be..5404c19 100644 --- a/lib/ghtorrent/retriever.rb +++ b/lib/ghtorrent/retriever.rb @@ -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 @@ -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?"