Skip to content
Open
Show file tree
Hide file tree
Changes from 4 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
30 changes: 29 additions & 1 deletion lib/ghtorrent/ghtorrent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def db
return @db unless @db.nil?

Sequel.single_threaded = true
Sequel.split_symbols = true
@db = Sequel.connect(config(:sql_url), :encoding => 'utf8')
#@db.loggers << Logger.new(STDOUT)
if @db.tables.empty?
Expand Down Expand Up @@ -1660,19 +1661,46 @@ def ensure_issue_comment(owner, repo, issue_id, comment_id, pull_req_id = nil)
end

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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm having a lot of trouble testing this code block because of the constraint violations mentioned in #52

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..."

reactions = retrieve_issue_comment(owner, repo, issue_id, comment_id)['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 @@ -71,4 +71,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