Skip to content
This repository was archived by the owner on May 5, 2021. It is now read-only.

Include pull request reviews in database #128

Merged
merged 1 commit into from
Sep 28, 2018
Merged
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
19 changes: 18 additions & 1 deletion db/lib/issueStoreLibrary.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,24 @@ def db_insert_comments(db, comments, org, repo)
end
end

def db_getMaxCommentTimestampForRepo(db, org, repo)
# Inserts new comments. If any exist already, it replaces them.
def db_insert_pr_reviews(db, comments, org, repo)
comments.each do |comment|
db["DELETE FROM item_comments WHERE id=?", comment.id].delete
# eg: https://github.com/amzn/oss-dashboard/pull/1#discussion_r207199796
itemNumber=comment.html_url.sub(/^.*\/([0-9]*)#discussion_r[0-9]*$/, '\1')
user=comment.user ? comment.user.login : nil
db[
"INSERT INTO item_comments (
id, org, repo, item_number, user_login, body, created_at, updated_at
)
VALUES ( ?, ?, ?, ?, ?, ?, ?, ? )",
comment.id, org, repo, itemNumber, user, comment.body, gh_to_db_timestamp(comment.created_at),
gh_to_db_timestamp(comment.updated_at)].insert
end
end

def db_getMaxCommentTimestampForRepo(db, org, repo)
# Normally '2015-04-18 14:17:02 UTC'
# Need '2015-04-18T14:17:02Z'
db["select max(updated_at) from item_comments where org='#{org}' and repo='#{repo}'"].each do |row|
Expand Down
3 changes: 3 additions & 0 deletions github-sync-tng/issue_comment_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,13 @@ def sync_item_comments(context, issue_db, org, repo)
# Increment the timestamp by a second to avoid getting repeats
ts=DateTime.strptime(maxTimestamp, '%Y-%m-%dT%H:%M:%S') + Rational(1, 60 * 60 * 24)
comments=context.client.issues_comments(orgrepo, { 'since' => ts } )
pr_reviews=context.client.pull_requests_comments(orgrepo, { 'since' => ts } )
else
comments=context.client.issues_comments(orgrepo)
pr_reviews=context.client.pull_requests_comments(orgrepo)
end
db_insert_comments(issue_db, comments, org, repo)
db_insert_pr_reviews(issue_db, pr_reviews, org, repo)
end
end

Expand Down
4 changes: 4 additions & 0 deletions github-sync/db_issues/sync-issues.rb
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,13 @@ def getLatestIssueComments(context, issue_db, org, repos)
# Increment the timestamp by a second to avoid getting repeats
ts=DateTime.strptime(maxTimestamp, '%Y-%m-%dT%H:%M:%S') + Rational(1, 60 * 60 * 24)
comments=context.client.issues_comments(repo_obj.full_name, { 'since' => ts } )
pr_reviews=context.client.pull_requests_comments(repo_obj.full_name, { 'since' => ts } )
else
comments=context.client.issues_comments(repo_obj.full_name)
pr_reviews=context.client.pull_requests_comments(repo_obj.full_name)
end
db_insert_comments(issue_db, comments, org, repo_obj.name)
db_insert_pr_reviews(issue_db, pr_reviews, org, repo_obj.name)
end
context.feedback.print '.'
end
Expand All @@ -171,3 +174,4 @@ def sync_issue_comments(context, sync_db)
end

end