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

Commit cd84433

Browse files
authored
Merge pull request #128 from MaineC/track-pr-reviews
Include pull request reviews in database
2 parents 578f3c1 + 687004c commit cd84433

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

db/lib/issueStoreLibrary.rb

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,24 @@ def db_insert_comments(db, comments, org, repo)
6161
end
6262
end
6363

64-
def db_getMaxCommentTimestampForRepo(db, org, repo)
64+
# Inserts new comments. If any exist already, it replaces them.
65+
def db_insert_pr_reviews(db, comments, org, repo)
66+
comments.each do |comment|
67+
db["DELETE FROM item_comments WHERE id=?", comment.id].delete
68+
# eg: https://github.com/amzn/oss-dashboard/pull/1#discussion_r207199796
69+
itemNumber=comment.html_url.sub(/^.*\/([0-9]*)#discussion_r[0-9]*$/, '\1')
70+
user=comment.user ? comment.user.login : nil
71+
db[
72+
"INSERT INTO item_comments (
73+
id, org, repo, item_number, user_login, body, created_at, updated_at
74+
)
75+
VALUES ( ?, ?, ?, ?, ?, ?, ?, ? )",
76+
comment.id, org, repo, itemNumber, user, comment.body, gh_to_db_timestamp(comment.created_at),
77+
gh_to_db_timestamp(comment.updated_at)].insert
78+
end
79+
end
80+
81+
def db_getMaxCommentTimestampForRepo(db, org, repo)
6582
# Normally '2015-04-18 14:17:02 UTC'
6683
# Need '2015-04-18T14:17:02Z'
6784
db["select max(updated_at) from item_comments where org='#{org}' and repo='#{repo}'"].each do |row|

github-sync-tng/issue_comment_command.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,13 @@ def sync_item_comments(context, issue_db, org, repo)
6060
# Increment the timestamp by a second to avoid getting repeats
6161
ts=DateTime.strptime(maxTimestamp, '%Y-%m-%dT%H:%M:%S') + Rational(1, 60 * 60 * 24)
6262
comments=context.client.issues_comments(orgrepo, { 'since' => ts } )
63+
pr_reviews=context.client.pull_requests_comments(orgrepo, { 'since' => ts } )
6364
else
6465
comments=context.client.issues_comments(orgrepo)
66+
pr_reviews=context.client.pull_requests_comments(orgrepo)
6567
end
6668
db_insert_comments(issue_db, comments, org, repo)
69+
db_insert_pr_reviews(issue_db, pr_reviews, org, repo)
6770
end
6871
end
6972

github-sync/db_issues/sync-issues.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,13 @@ def getLatestIssueComments(context, issue_db, org, repos)
147147
# Increment the timestamp by a second to avoid getting repeats
148148
ts=DateTime.strptime(maxTimestamp, '%Y-%m-%dT%H:%M:%S') + Rational(1, 60 * 60 * 24)
149149
comments=context.client.issues_comments(repo_obj.full_name, { 'since' => ts } )
150+
pr_reviews=context.client.pull_requests_comments(repo_obj.full_name, { 'since' => ts } )
150151
else
151152
comments=context.client.issues_comments(repo_obj.full_name)
153+
pr_reviews=context.client.pull_requests_comments(repo_obj.full_name)
152154
end
153155
db_insert_comments(issue_db, comments, org, repo_obj.name)
156+
db_insert_pr_reviews(issue_db, pr_reviews, org, repo_obj.name)
154157
end
155158
context.feedback.print '.'
156159
end
@@ -171,3 +174,4 @@ def sync_issue_comments(context, sync_db)
171174
end
172175

173176
end
177+

0 commit comments

Comments
 (0)