Browse Source

Add option to hide certain comments

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

Change-Id: I3cba63efa0b1032c9ac4df5551fcf157a0909745
changes/67/115767/3
James E. Blair 7 years ago
parent
commit
ccc2a3eebf
  1. 5
      gertty.yaml-sample
  2. 10
      gertty/config.py
  3. 32
      gertty/view/change.py

5
gertty.yaml-sample

@ -41,6 +41,11 @@ commentlinks:
# of the default side-by-side:
# 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:
- name: "My changes"
query: "owner:self status:open"

10
gertty/config.py

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

32
gertty/view/change.py

@ -289,6 +289,7 @@ class ChangeView(urwid.WidgetWrap):
<n> Go to the next change in the list.
<p> Go to the previous change in the list.
<r> Leave a review for the most recent revision.
<t> Toggle display of hidden comments.
<u> Back to the list of changes.
<v> Toggle the reviewed flag for the current change.
<x> Cherry-pick the most recent revision onto the local repo.
@ -310,6 +311,7 @@ class ChangeView(urwid.WidgetWrap):
self.revision_rows = {}
self.message_rows = {}
self.last_revision_key = None
self.hide_comments = True
self.change_id_label = urwid.Text(u'', wrap='clip')
self.owner_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
if len(self.listbox.body) == listbox_index:
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:
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)
if not row:
box = ChangeMessageBox(self.app, message)
row = urwid.Padding(box, width=80)
self.listbox.body.insert(listbox_index, row)
self.message_rows[message.key] = row
# Messages are extremely unlikely to be deleted, skip
# that case.
else:
unseen_keys.remove(message.key)
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):
if not changes:
@ -607,6 +629,10 @@ class ChangeView(urwid.WidgetWrap):
except gertty.view.DisplayError as e:
self.app.error(e.message)
return None
if r == 't':
self.hide_comments = not self.hide_comments
self.refresh()
return None
if r == 'ctrl r':
self.app.sync.submitTask(
sync.SyncChangeTask(self.change_rest_id, priority=sync.HIGH_PRIORITY))

Loading…
Cancel
Save