Skip to content

Instantly share code, notes, and snippets.

Last active May 19, 2016
What would you like to do?
Python script to pull all reviews a user has commented on Works with Review Board 2.0.18
#!/usr/bin/env python2.6
Python script to pull all reviews a user has commented on
Works with Review Board 2.0.18
import site
import json
import time
import dateutil
import linkedin.cli
from linkedin.reviewboard.rbutils import REVIEWBOARD_URL, rb_request
def datetime_to_rb(dt):
return dt.isoformat()
def make_rb_api_url(resource):
return REVIEWBOARD_URL + '/api/' + resource
def reviews_comment_on(userid, start_time, end_time):
commented_on_list = []
request_params = {'status': 'all',
'to-users': userid,
'last-updated-from': start_time,
'last-updated-to': end_time}
finished = False
review_request_list_resource = rb_request(make_rb_api_url('review-requests/'), params=request_params)
while not finished:
for review_request_resource in review_request_list_resource['review_requests']:
rb_id = review_request_resource['id']
review_list_resource_url = review_request_resource['links']['reviews']['href']
summary = review_request_resource['summary']
originator = review_request_resource['links']['submitter']['title']
review_list_resource = rb_request(review_list_resource_url)
for comments in review_list_resource['reviews']:
if comments['links']['user']['title'] == userid:
commented_on_list.append({'id': rb_id,
'originator': originator,
'summary': summary})
# Only need to see one comment before adding to the list
if review_request_list_resource['links'].has_key('next'):
review_request_list_resource = rb_request(review_request_list_resource['links']['next']['href'])
finished = True
return commented_on_list
def dump_to_screen(rb_list):
for rb in rb_list:
print '%s %8s %s' % (rb['id'], rb['id'], rb['originator'], rb['summary'])
except UnicodeEncodeError as u:
def dump_json(rb_list):
print json.dumps(rb_list)
def main(cli):
cli.add_argument('--updated-from', action='store', required=True,
help='Time to begin search of reviews. Format is ISO8601, {yyyy}-{mm}-{dd}T{HH}:{MM}:{SS}.')
cli.add_argument('--updated-to', action='store', required=True,
help='Time to end search of reviews. Format is ISO8601, {yyyy}-{mm}-{dd}T{HH}:{MM}:{SS}.')
cli.add_argument('--userid', action='store', required=True,
help='Userid of the user to search for reviews commented on.')
cli.add_argument('--json', action='store_true', default=False,
help='If set, output is dumped in json format.')
userid = cli.args.userid
# Try and parse the date to handle any strange input
# instead of explicitly verifying the format
start_period_dt = dateutil.parser.parse(cli.args.updated_from)
start_period = datetime_to_rb(start_period_dt)
end_period_dt = dateutil.parser.parse(cli.args.updated_to)
end_period = datetime_to_rb(end_period_dt)
if not cli.args.json:
print 'Running on %s from %r until %r' % (userid, start_period, end_period)
list_of_reviews_commented_on = reviews_comment_on(userid, start_period, end_period)
if cli.args.json:
# python --updated-from 2014-04-01 --updated-to 2016-05-13 --userid rdsr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment