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

Commit a9ea5d3

Browse files
committed
Include pull request reviews in database
This extends github-sync to also store pull request reviews in the database.
1 parent bc6138d commit a9ea5d3

File tree

5 files changed

+60
-3
lines changed

5 files changed

+60
-3
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|

docs/Running.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ Available phases are:
3535
| github-sync/events | Syncs only the event stream |
3636
| github-sync/issues | Syncs the issue data - note that this is typically the heaviest initial load |
3737
| github-sync/issue-comments | Syncs the issue comments |
38+
| github-sync/pr-reviews | Syncs the pr reviews |
3839
| github-sync/releases | Syncs the release data |
3940
| github-sync/user-mapping | Loads your user-mapping file into the database |
4041
| github-sync/reporting | Runs the configured DB Reports |

github-sync/db_issues/sync-issues.rb

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,27 @@ def getLatestIssueComments(context, issue_db, org, repos)
157157
end
158158
end
159159

160+
def getLatestPRReviews(context, issue_db, org, repos)
161+
repos.each do |repo_obj|
162+
begin
163+
issue_db.transaction do
164+
# Get the current max timestamp in the db
165+
maxTimestamp=db_getMaxCommentTimestampForRepo(issue_db, org, repo_obj.name)
166+
if(maxTimestamp)
167+
# Increment the timestamp by a second to avoid getting repeats
168+
ts=DateTime.strptime(maxTimestamp, '%Y-%m-%dT%H:%M:%S') + Rational(1, 60 * 60 * 24)
169+
comments=context.client.pull_requests_comments(repo_obj.full_name, { 'since' => ts } )
170+
else
171+
comments=context.client.pull_requests_comments(repo_obj.full_name)
172+
end
173+
db_insert_pr_reviews(issue_db, comments, org, repo_obj.name)
174+
end
175+
context.feedback.print '.'
176+
end
177+
end
178+
end
179+
180+
160181
def sync_issue_comments(context, sync_db)
161182

162183
owners = context.dashboard_config['organizations+logins']
@@ -171,3 +192,17 @@ def sync_issue_comments(context, sync_db)
171192
end
172193

173194
end
195+
196+
def sync_pr_reviews(context, sync_db)
197+
owners = context.dashboard_config['organizations+logins']
198+
context.feedback.puts " pull-request-reviews"
199+
200+
owners.each do |org|
201+
repos=context.repositories(org)
202+
203+
context.feedback.print " #{org} "
204+
getLatestPRReviews(context, sync_db, org, repos)
205+
context.feedback.print "\n"
206+
end
207+
208+
end

github-sync/sync.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ def github_sync(context, run_one)
6969
# TODO: Move to being based on the async code
7070
sync_issue_comments(context, sync_db)
7171
end
72+
if(not(run_one) or run_one=='github-sync/pr-reviews')
73+
# TODO: Implement async code
74+
sync_pr_reviews(context, sync_db)
75+
end
7276
if(not(run_one) or run_one=='github-sync/releases')
7377
# TODO: Move to being based on the async code
7478
sync_releases(context, sync_db)

refresh-dashboard.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929

3030
def xml2html(context, xmlFiles, xsltFile, outputDirectory)
3131
Dir.glob(xmlFiles).each do |inputFile|
32-
stylesheet = LibXSLT::XSLT::Stylesheet.new( LibXML::XML::Document.file(xsltFile))
3332
xml_doc = LibXML::XML::Document.file(inputFile)
33+
stylesheet = LibXSLT::XSLT::Stylesheet.new( LibXML::XML::Document.file(xsltFile))
3434
html = stylesheet.apply(xml_doc)
3535

3636
outputFile=File.basename(inputFile, ".xml")
@@ -136,7 +136,7 @@ def xml2html(context, xmlFiles, xsltFile, outputDirectory)
136136

137137
# TODO: Implement github-sync and generate-dashboard as aliases?
138138
allPhases=['init-database', 'github-sync', 'pull-source', 'review-source', 'generate-dashboard']
139-
legitPhases=['init-database', 'github-sync/metadata', 'github-sync/commits', 'github-sync/events', 'github-sync/issues', 'github-sync/issue-comments', 'github-sync/releases', 'github-sync/traffic', 'github-sync/user-mapping', 'github-sync/reporting', 'pull-source', 'review-source', 'generate-dashboard/xml', 'generate-dashboard/json-data', 'generate-dashboard/dashboards', 'generate-dashboard/xslt', 'github-sync', 'generate-dashboard']
139+
legitPhases=['init-database', 'github-sync/metadata', 'github-sync/commits', 'github-sync/events', 'github-sync/issues', 'github-sync/issue-comments', 'github-sync/pr-reviews', 'github-sync/releases', 'github-sync/traffic', 'github-sync/user-mapping', 'github-sync/reporting', 'pull-source', 'review-source', 'generate-dashboard/xml', 'generate-dashboard/json-data', 'generate-dashboard/dashboards', 'generate-dashboard/xslt', 'github-sync', 'generate-dashboard']
140140

141141
if(ARGV[1])
142142
run_list=ARGV[1..-1]

0 commit comments

Comments
 (0)