# HG changeset patch # User Jeff Hammel # Date 1379621043 25200 # Node ID a5b7ea791f643bd4fe82efaba0f76d5e52fe6725 # Parent 39325717218d3d833d9b4b36a62525b946860e83 bzconsole/api.py diff -r 39325717218d -r a5b7ea791f64 bzconsole/api.py --- a/bzconsole/api.py Thu Sep 19 10:55:13 2013 -0700 +++ b/bzconsole/api.py Thu Sep 19 13:04:03 2013 -0700 @@ -25,6 +25,7 @@ def __init__(self, server='https://api-dev.bugzilla.mozilla.org/latest', + base_url='https://bugzilla.mozilla.org', refresh=False, print_request=None, username=None, @@ -34,6 +35,7 @@ - print_request : log any request information to a file """ self.server = server + self.base_url = base_url.rstrip('/') self.refresh = refresh self.print_request = print_request self.username = username @@ -78,6 +80,47 @@ number = int(number) return self._request('/bug/%d' % number) + def comments(self, bug, comment=None): + """ + display a bug's comments + - comment: comment # to display + """ + + bug = int(bug) + if comment: + if isinstance(comment, basestring): + comment = [comment] + comment = [int(c) for c in comment] + raise NotImplementedError("TODO") + else: + return self._request('/bug/%d/comment' % bug)['comments'] + + def log(self, bug, reverse=True, lines=2, limit=None): + """brief comment log""" + bug = int(bug) + comments = list(enumerate(self.comments(bug))) + if reverse: + comments.reverse() + if limit is not None: + comments = comments[:limit] + template = "%(url)s\n%(author)s %(datetime)s \n%(text)s" + output = [] + for index, comment in comments: + text = '\n'.join([line.strip() if len(line) < 79 else line[:79] + '...' + for line in comment['text'].splitlines()[:lines] + if line.strip()]) + vals = dict(url='%s/show_bug.cgi?id=%d#c%d' % (self.base_url, bug, index), + datetime=comment['creation_time'], + author=comment['creator']['name'], + text=text) + output.append(template % vals) + + return '\n\n'.join(output) + + def top(self, bug, lines=2, limit=4): + """latest comments""" + return self.log(bug, lines=lines, limit=limit, reverse=True) + def summary(self, number): """ display bug summary: