Mercurial > hg > bzconsole
changeset 55:a5b7ea791f64
bzconsole/api.py
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Thu, 19 Sep 2013 13:04:03 -0700 |
parents | 39325717218d |
children | baecb5a6f05b |
files | bzconsole/api.py |
diffstat | 1 files changed, 43 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- 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: