Commits

iproetel committed 6f657c5

New command 'qreviews' to show currently pending reviews on patches.

Comments (0)

Files changed (2)

+# HG changeset patch
+# Parent ac6ddd9c492f8c0a5a99b92729e84c91cbf8ce0e
+diff -r ac6ddd9c492f -r 07b176e4ac4b mercurial_reviewboard/__init__.py
+--- a/mercurial_reviewboard/__init__.py	Tue Jul 05 18:10:02 2011 +0200
++++ b/mercurial_reviewboard/__init__.py	Tue Aug 02 18:13:00 2011 +0200
+@@ -97,7 +97,7 @@
+     rev = patchinfo[1];
+     request_id = do_postreview(ui, repo, rev, opts)
+ 
+-    # for new requests the request_id gets stroed in the series file of mq
++    # for new requests the request_id gets stored in the series file of mq
+     if len(existing) == 0 :
+         repo.mq.full_series[index] += ' #posted:' + str(request_id)
+         repo.mq.parse_series()
+@@ -111,6 +111,66 @@
+         repo.mq.series_dirty = True
+         repo.mq.save_dirty()
+ 
++def qreviews(ui, repo, patch=None, **opts):#
++    ''' Show pending review requests for the patches.
++    '''
++    patches = []
++    if patch:
++      # search for a patch that matches the name, tag, etc.
++      patch = repo.mq.lookup(patch)
++      ui.debug('found patch:%s\n' % str(patch))
++      index = repo.mq.find_series(patch)
++      existing = posted_re.findall(repo.mq.full_series[index])
++      if existing:
++          patches.append((patch,existing[0]))
++    else:
++      ui.debug('look for all  patches:%s\n' % str(patch))
++      for index, full_patch in enumerate(repo.mq.full_series):
++          existing = posted_re.findall(full_patch)
++          if existing:
++            patches.append((repo.mq.series[index],existing[0]))
++
++    if len(patches) > 0:
++      # checks to see if the server was set
++      find_server(ui, opts)
++      reviewboard = getreviewboard(ui, opts)
++
++      results = []
++      for review in patches:
++        patchinfo = repo.mq.isapplied(patch)
++        last_reviewer = ''
++        all_reviews = reviewboard.get_reviews(review[1])
++        if len(all_reviews) > 0:
++          last_reviewer = str(all_reviews[len(all_reviews)-1]['links']['user']['title'])
++        ship_its = [r for r in all_reviews if r['ship_it']]
++        if len(ship_its) > 0:
++          last_reviewer = str(ship_its[len(ship_its)-1]['links']['user']['title'])
++        results.append((review[0], review[1], len(all_reviews), len(ship_its), last_reviewer))
++
++      maxLen = max(len(result[0]) for result in results)
++
++      ui.status("applied     review id      sign off\n")
++      ui.status("   patchname       last reviewer\n")
++      ui.status("-----------------------------------\n")
++      for result in results:
++        patchname = result[0]
++        reviewID  = result[1]
++        reviewStatus = reviewboard.get_status(reviewID)
++        if not reviewStatus == 'pending':
++          if reviewStatus == 'submitted':
++            reviewID = '['+reviewID+']'
++          else: # 'discarded'
++            reviewID = '-'+reviewID+'-'
++        reviewCount = result[2]
++        if result[3] > 0:
++          ship_it = "ship_it"
++        else:
++          ship_it = "       "
++
++        if repo.mq.isapplied(patchname):
++          ui.status("> %s %s %s %s\n" % (patchname.ljust(maxLen), reviewID.center(6), result[4], ship_it))
++        else:
++          ui.status("  %s %s %s %s\n" % (patchname.ljust(maxLen), reviewID.center(6), result[4], ship_it))
+ 
+ def do_postreview(ui, repo, rev, opts):
+     # checks to see if the server was set
+@@ -576,3 +636,14 @@
+          # -i/--interactive for qrecord and add white space diff options
+          cmdtable['postreview'][1][:],
+          _('hg qpostreview [OPTION]... PATCH'))
++
++    cmdtable["qreviews"] = \
++        (qreviews,
++         # same options as qnew, but copy them so we don't get
++         # -i/--interactive for qrecord and add white space diff options
++        [
++        ('', 'server', '', _('ReviewBoard server URL')),
++        ('', 'username', '', _('username for the ReviewBoard site')),
++        ('', 'password', '', _('password for the ReviewBoard site')),
++        ],
++         _('hg qreviews [OPTION]... PATCH'))
+\ No newline at end of file
+diff -r ac6ddd9c492f -r 07b176e4ac4b mercurial_reviewboard/reviewboard.py
+--- a/mercurial_reviewboard/reviewboard.py	Tue Jul 05 18:10:02 2011 +0200
++++ b/mercurial_reviewboard/reviewboard.py	Tue Aug 02 18:13:00 2011 +0200
+@@ -362,6 +362,9 @@
+         fields['status'] = status
+         self._api_request('PUT', '/api/review-requests/%s/' % id, fields)
+ 
++    def get_reviews(self, id):
++        rsp = self._api_request('GET', '/api/review-requests/%s/reviews/' % id)
++        return rsp['reviews']
+ 
+     def _create_request(self, repo_id):
+         data = { 'repository': repo_id }
 qpostreview.patch
 short-description.patch
 check-state.patch
+qreviews.patch
+