public
anonymous / reviewboard.py
Created

Fixes the TortoiseHG Reviewboard extension to support the Update Review functionality accessed via the TortoiseHG Reviewboard UI.

  • Download Gist
reviewboard.py
Python
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
diff -r 7a4fb18e6bc0 reviewboard.py
--- a/reviewboard.py Mon Feb 04 10:48:09 2013 -0800
+++ b/reviewboard.py Wed Feb 20 11:37:58 2013 +0100
@@ -5,6 +5,8 @@
import getpass
import mimetools
import os
+import datetime
+import urllib
import urllib2
import simplejson
import mercurial.ui
@@ -58,6 +60,14 @@
self.tool = tool
self.path = path
+class Request:
+ """
+ Represents a ReviewBoard request
+ """
+ def __init__(self, id, summary):
+ self.id = id
+ self.summary = summary
+
class ReviewBoardHTTPPasswordMgr(urllib2.HTTPPasswordMgr):
"""
Adds HTTP authentication support for URLs.
@@ -288,6 +298,7 @@
def __init__(self, httpclient):
ApiClient.__init__(self, httpclient)
self._repositories = None
+ self._pending_user_requests = None
self._requestcache = {}
def login(self, username=None, password=None):
@@ -302,6 +313,24 @@
for r in rsp['repositories']]
return self._repositories
+ def pending_user_requests(self):
+ if not self._pending_user_requests:
+ usr = str(self._httpclient._password_mgr.rb_user)
+ delta = datetime.timedelta(days=7)
+ today = datetime.datetime.today()
+ sevenDaysAgo = today - delta
+ date_str = urllib.quote(sevenDaysAgo) #fixes " " to "%20"
+ rsp = self._api_request('GET', '/api/review-requests/' +
+ '?from-user=%s' % usr +
+ '&status=pending' +
+ '&max-results=50' +
+ '&last-updated-from=%s' % date_str)
+ self._pending_user_requests = []
+
+ for r in rsp['review_requests']:
+ self._pending_user_requests += [Request(r['id'], r['summary'].strip())]
+ return self._pending_user_requests
+
def new_request(self, repo_id, fields={}, diff='', parentdiff=''):
req = self._create_request(repo_id)
self._set_request_details(req, fields, diff, parentdiff)

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.