Add option to hide certain comments

The example configuration hides comments from CI systems.  The 't'
key will toggle their display.

Change-Id: I3cba63efa0b1032c9ac4df5551fcf157a0909745
This commit is contained in:
James E. Blair 2014-08-19 17:47:13 -07:00
parent 710afa5b45
commit ccc2a3eebf
3 changed files with 44 additions and 3 deletions

View File

@ -41,6 +41,11 @@ commentlinks:
# of the default side-by-side: # of the default side-by-side:
# diff-view: unified # diff-view: unified
# Hide comments by default that match the following criteria.
# You can toggle their display with 't'.
hide-comments:
- author: "^(.*CI|Jenkins)$"
dashboards: dashboards:
- name: "My changes" - name: "My changes"
query: "owner:self status:open" query: "owner:self status:open"

View File

@ -16,6 +16,7 @@
import collections import collections
import getpass import getpass
import os import os
import re
try: try:
import ordereddict import ordereddict
except: except:
@ -83,6 +84,10 @@ class ConfigSchema(object):
reviewkeys = [reviewkey] reviewkeys = [reviewkey]
hide_comment = {v.Required('author'): str}
hide_comments = [hide_comment]
def getSchema(self, data): def getSchema(self, data):
schema = v.Schema({v.Required('servers'): self.servers, schema = v.Schema({v.Required('servers'): self.servers,
'palettes': self.palettes, 'palettes': self.palettes,
@ -91,6 +96,7 @@ class ConfigSchema(object):
'reviewkeys': self.reviewkeys, 'reviewkeys': self.reviewkeys,
'change-list-query': str, 'change-list-query': str,
'diff-view': str, 'diff-view': str,
'hide-comments': self.hide_comments,
}) })
return schema return schema
@ -155,6 +161,10 @@ class Config(object):
for k in self.config.get('reviewkeys', []): for k in self.config.get('reviewkeys', []):
self.reviewkeys[k['key']] = k self.reviewkeys[k['key']] = k
self.hide_comments = []
for h in self.config.get('hide-comments', []):
self.hide_comments.append(re.compile(h['author']))
def getServer(self, name=None): def getServer(self, name=None):
for server in self.config['servers']: for server in self.config['servers']:
if name is None or name == server['name']: if name is None or name == server['name']:

View File

@ -289,6 +289,7 @@ class ChangeView(urwid.WidgetWrap):
<n> Go to the next change in the list. <n> Go to the next change in the list.
<p> Go to the previous change in the list. <p> Go to the previous change in the list.
<r> Leave a review for the most recent revision. <r> Leave a review for the most recent revision.
<t> Toggle display of hidden comments.
<u> Back to the list of changes. <u> Back to the list of changes.
<v> Toggle the reviewed flag for the current change. <v> Toggle the reviewed flag for the current change.
<x> Cherry-pick the most recent revision onto the local repo. <x> Cherry-pick the most recent revision onto the local repo.
@ -310,6 +311,7 @@ class ChangeView(urwid.WidgetWrap):
self.revision_rows = {} self.revision_rows = {}
self.message_rows = {} self.message_rows = {}
self.last_revision_key = None self.last_revision_key = None
self.hide_comments = True
self.change_id_label = urwid.Text(u'', wrap='clip') self.change_id_label = urwid.Text(u'', wrap='clip')
self.owner_label = urwid.Text(u'', wrap='clip') self.owner_label = urwid.Text(u'', wrap='clip')
self.project_label = urwid.Text(u'', wrap='clip') self.project_label = urwid.Text(u'', wrap='clip')
@ -481,17 +483,37 @@ class ChangeView(urwid.WidgetWrap):
listbox_index += 1 listbox_index += 1
if len(self.listbox.body) == listbox_index: if len(self.listbox.body) == listbox_index:
self.listbox.body.insert(listbox_index, urwid.Divider()) self.listbox.body.insert(listbox_index, urwid.Divider())
listbox_index += 1 listbox_index += 1
# Get the set of messages that should be displayed
display_messages = []
for message in change.messages: for message in change.messages:
skip = False
if self.hide_comments:
for regex in self.app.config.hide_comments:
if regex.match(message.author.name):
skip = True
break
if not skip:
display_messages.append(message)
# The set of message keys currently displayed
unseen_keys = set(self.message_rows.keys())
# Make sure all of the messages that should be displayed are
for message in display_messages:
row = self.message_rows.get(message.key) row = self.message_rows.get(message.key)
if not row: if not row:
box = ChangeMessageBox(self.app, message) box = ChangeMessageBox(self.app, message)
row = urwid.Padding(box, width=80) row = urwid.Padding(box, width=80)
self.listbox.body.insert(listbox_index, row) self.listbox.body.insert(listbox_index, row)
self.message_rows[message.key] = row self.message_rows[message.key] = row
# Messages are extremely unlikely to be deleted, skip else:
# that case. unseen_keys.remove(message.key)
listbox_index += 1 listbox_index += 1
# Remove any messages that should not be displayed
for key in unseen_keys:
row = self.message_rows.get(key)
self.listbox.body.remove(row)
del self.message_rows[key]
listbox_index -= 1
def _updateDependenciesWidget(self, changes, widget, widget_rows, header): def _updateDependenciesWidget(self, changes, widget, widget_rows, header):
if not changes: if not changes:
@ -607,6 +629,10 @@ class ChangeView(urwid.WidgetWrap):
except gertty.view.DisplayError as e: except gertty.view.DisplayError as e:
self.app.error(e.message) self.app.error(e.message)
return None return None
if r == 't':
self.hide_comments = not self.hide_comments
self.refresh()
return None
if r == 'ctrl r': if r == 'ctrl r':
self.app.sync.submitTask( self.app.sync.submitTask(
sync.SyncChangeTask(self.change_rest_id, priority=sync.HIGH_PRIORITY)) sync.SyncChangeTask(self.change_rest_id, priority=sync.HIGH_PRIORITY))