From f4118833af83aab37d4b4c8514a4b0b09d7e1d90 Mon Sep 17 00:00:00 2001 From: "James E. Blair" Date: Sat, 23 Aug 2014 10:38:03 -0700 Subject: [PATCH] Add test results to top of change view Add an option to commentlinks to indicate they are test results and use that to collect results and display them at the top of the change view. The value of 'test-results' is used as the job key when creating the table (so that only the most recent result for a given job run on the latest patchset is included). This is particularly effective along with the hide-comment system to hide the results from the comment stream. Change-Id: I54a787914aab18ad2a2a5ca4cc79dd66add2c588 --- gertty.yaml-sample | 5 +++-- gertty/commentlink.py | 23 +++++++++++++++++++++++ gertty/config.py | 3 ++- gertty/mywid.py | 17 +++++++++++++++++ gertty/view/change.py | 24 ++++++++++++++++++++++-- 5 files changed, 67 insertions(+), 5 deletions(-) diff --git a/gertty.yaml-sample b/gertty.yaml-sample index 78fe0f4..479a6de 100644 --- a/gertty.yaml-sample +++ b/gertty.yaml-sample @@ -16,7 +16,8 @@ palettes: test-FAILURE: ['light red', '', ''] commentlinks: - - match: "^- (?P.*?) (?P.*?) : (?P.*?) (?P.*)$" + - match: "^- (?P.*?) (?P.*?) : (?P[^ ]+) ?(?P.*)$" + test-result: "{job}" replacements: - link: text: "{job:<42}" @@ -24,7 +25,7 @@ commentlinks: - text: color: "test-{result}" text: "{result} " - - text: "{rest}" + - text: "{comment}" - match: "(?PI[0-9a-fA-F]{40})" replacements: - search: diff --git a/gertty/commentlink.py b/gertty/commentlink.py index 4be27b3..97c2d46 100644 --- a/gertty/commentlink.py +++ b/gertty/commentlink.py @@ -12,12 +12,22 @@ # License for the specific language governing permissions and limitations # under the License. +import collections +try: + import ordereddict +except: + pass import re import urwid import mywid +try: + OrderedDict = collections.OrderedDict +except AttributeError: + OrderedDict = ordereddict.OrderedDict + class TextReplacement(object): def __init__(self, config): if isinstance(config, basestring): @@ -57,6 +67,7 @@ class SearchReplacement(object): class CommentLink(object): def __init__(self, config): self.match = re.compile(config['match'], re.M) + self.test_result = config.get('test-result', None) self.replacements = [] for r in config['replacements']: if 'text' in r: @@ -66,6 +77,18 @@ class CommentLink(object): if 'search' in r: self.replacements.append(SearchReplacement(r['search'])) + def getTestResults(self, app, text): + if self.test_result is None: + return {} + ret = OrderedDict() + for line in text.split('\n'): + m = self.match.search(line) + if m: + repl = [r.replace(app, m.groupdict()) for r in self.replacements] + job = self.test_result.format(**m.groupdict()) + ret[job] = repl + ['\n'] + return ret + def run(self, app, chunks): ret = [] for chunk in chunks: diff --git a/gertty/config.py b/gertty/config.py index 7fea291..6c0cab6 100644 --- a/gertty/config.py +++ b/gertty/config.py @@ -66,7 +66,8 @@ class ConfigSchema(object): palettes = [palette] commentlink = {v.Required('match'): str, - v.Required('replacements'): [replacement]} + v.Required('replacements'): [replacement], + 'test-result': str} commentlinks = [commentlink] diff --git a/gertty/mywid.py b/gertty/mywid.py index 12d986a..71263ca 100644 --- a/gertty/mywid.py +++ b/gertty/mywid.py @@ -276,3 +276,20 @@ class Link(urwid.Widget): if focus: return self.focused_attr return self.attr + +# A workaround for the issue fixed in +# https://github.com/wardi/urwid/pull/74 +# included here until thi fix is released +class MyGridFlow(urwid.GridFlow): + def generate_display_widget(self, size): + p = super(MyGridFlow, self).generate_display_widget(size) + for item in p.contents: + if isinstance(item[0], urwid.Padding): + c = item[0].original_widget + if isinstance(c, urwid.Columns): + if c.focus_position == 0 and not c.contents[0][0].selectable(): + for i, w in enumerate(c.contents): + if w[0].selectable(): + c.focus_position = i + break + return p diff --git a/gertty/view/change.py b/gertty/view/change.py index 9047c40..0fa7e1e 100644 --- a/gertty/view/change.py +++ b/gertty/view/change.py @@ -340,8 +340,9 @@ class ChangeView(urwid.WidgetWrap): self.needed_by = urwid.Pile([]) self.needed_by_rows = {} self.related_changes = urwid.Pile([self.depends_on, self.needed_by]) - self.grid = urwid.GridFlow([change_info, self.commit_message, votes], - cell_width=80, h_sep=2, v_sep=1, align='left') + self.results = mywid.HyperText(u'') # because it scrolls better than a table + self.grid = mywid.MyGridFlow([change_info, self.commit_message, votes, self.results], + cell_width=80, h_sep=2, v_sep=1, align='left') self.listbox = urwid.ListBox(urwid.SimpleFocusListWalker([])) self._w.contents.append((self.app.header, ('pack', 1))) self._w.contents.append((urwid.Divider(), ('pack', 1))) @@ -486,7 +487,15 @@ class ChangeView(urwid.WidgetWrap): listbox_index += 1 # Get the set of messages that should be displayed display_messages = [] + result_systems = {} for message in change.messages: + if message.revision == change.revisions[-1]: + for commentlink in self.app.config.commentlinks: + results = commentlink.getTestResults(self.app, message.message) + if results: + result_system = result_systems.get(message.author.name, {}) + result_systems[message.author.name] = result_system + result_system.update(results) skip = False if self.hide_comments: for regex in self.app.config.hide_comments: @@ -514,6 +523,17 @@ class ChangeView(urwid.WidgetWrap): self.listbox.body.remove(row) del self.message_rows[key] listbox_index -= 1 + self._updateTestResults(result_systems) + + def _updateTestResults(self, result_systems): + text = [] + for system, results in result_systems.items(): + for job, result in results.items(): + text.append(result) + if text: + self.results.set_text(text) + else: + self.results.set_text('') def _updateDependenciesWidget(self, changes, widget, widget_rows, header): if not changes: