Skip to content

Instantly share code, notes, and snippets.

@tchap
Created May 21, 2015 10:33
Show Gist options
  • Save tchap/81e41f0f63eae825a6cf to your computer and use it in GitHub Desktop.
Save tchap/81e41f0f63eae825a6cf to your computer and use it in GitHub Desktop.
import csv
import json
import os
import subprocess
import sys
RB_SERVER = 'https://review.salsitasoft.com'
repository = sys.argv[1]
data = json.loads(subprocess.check_output(['rbt', 'api-get', '--server', RB_SERVER, '/review-requests', '--repository=' + repository, '--status=all']))
rrs = data['review_requests']
rows = []
for rr in rrs:
row = {
'Review ID': rr['id'],
'Summary': rr['summary'],
'Branch': rr['branch'],
'Submitter': rr['links']['submitter']['title'],
}
data = json.loads(subprocess.check_output(['rbt', 'api-get', '--server', RB_SERVER, '/review-requests/{0}/diffs'.format(rr['id'])]))
diffs = data['diffs']
if len(diffs) != 0:
changes = 0
diff = diffs[-1]
data = json.loads(subprocess.check_output(['rbt', 'api-get', '--server', RB_SERVER, diff['links']['files']['href']]))
files = data['files']
for f in files:
extra = f['extra_data']
for field in ('insert_count', 'replace_count', 'delete_count'):
try:
changes += extra[field]
except KeyError:
pass
row['Lines Changed'] = changes
if rr['approved']:
data = json.loads(subprocess.check_output(['rbt', 'api-get', '--server', RB_SERVER, '/review-requests/{0}/reviews'.format(rr['id'])]))
for review in reversed(data['reviews']):
if review['ship_it']:
row['Reviewer'] = review['links']['user']['title']
row['Approved Timestamp'] = review['timestamp']
rows.append(row)
with open('./rbdump.csv', 'w') as csvfile:
writer = csv.DictWriter(csvfile, fieldnames=['Review ID', 'Summary', 'Branch', 'Lines Changed', 'Submitter', 'Reviewer', 'Approved Timestamp'])
writer.writeheader()
for row in rows:
writer.writerow(row)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment