Skip to content

Commit

Permalink
Add TTM message support
Browse files Browse the repository at this point in the history
  • Loading branch information
asdil12 committed May 24, 2018
1 parent 6e59f40 commit a331f31
Showing 1 changed file with 72 additions and 0 deletions.
72 changes: 72 additions & 0 deletions suse_msg/meta/ttm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import logging
import re
from collections import deque
from suse_msg.meta import BaseProcessor


logging.basicConfig(level=logging.INFO)


MSG_LIMIT = 60

# limit of how many times a truncated message has to show up the same before we repeat it
SEEN_LIMIT = 1
SEEN = deque(maxlen=SEEN_LIMIT)

def truncate(s):
if len(s) > MSG_LIMIT:
s = s[0:MSG_LIMIT] + '…'
return s


def comma_entries(l):
if type(l) is not list:
return l
return ', '.join(l)


class TTMProcessor(BaseProcessor):
topic_regex = r"(?P<scope>[^.]+)\.ttm\.(?P<object>[^.]+)\.(?P<event>[^.]+)"

def prepare(self):
m = re.match(type(self).topic_regex, self.topic)
self.scope = m.group('scope')
self.object = m.group('object')
self.event = m.group('event')

def fmt(self, c):
if self.object != 'build':
# only build object output is implemented
return ''

s = "TTM: %s build %s " % (self.msg['project'], self.msg['build'])
s += self.colored_result(c)

if self.event != 'pass':
if len(self.msg['failed_jobs']['relevant']) == 0:
s += " - not unknown fails" + ' yet!' if self.event == 'inprogress' else '!'
else:
s += " - unknown fails: "
s += truncate(' '.join(["%st%i" % (self.base_url(), buildid) for buildid in self.msg['failed_jobs']['relevant']]))

if s in SEEN:
logging.info("Ignoring already seen message '%s'" % s)
return ''
else:
logging.info("not found s in self.seen. self.seen: %s" % SEEN)
SEEN.append(s)
return s

def colored_result(self, c):
color = {
"fail": "lightred",
"pass": "lightgreen",
"inprogress": "yellow",
}.get(self.event, None)
return c(self.event, color)

def base_url(self):
if self.scope == 'suse':
return 'https://openqa.suse.de/'
elif self.scope == 'opensuse':
return 'https://openqa.opensuse.org/'

0 comments on commit a331f31

Please sign in to comment.