diff --git a/bugzilla/bugzilla-to-irker.py b/bugzilla/bugzilla-to-irker.py --- a/bugzilla/bugzilla-to-irker.py +++ b/bugzilla/bugzilla-to-irker.py @@ -40,31 +40,48 @@ self.bugNumber = subjectContents.group(2) self.shortDescription = subjectContents.group(4) - def summary(self): + def summary(self, compact): # For new bugs we use a different template (just for convenience) - if self.messageType == 'new': - template = 'New bug %(bugNumber)s in %(product)s (%(component)s) filed by %(changedBy)s [%(priority)s - %(severity)s]:\n%(shortDescription)s\nhttps://bugs.kde.org/%(bugNumber)s' + if compact: + if self.messageType == 'new': + template = 'New bug %(bugNumber)s in %(product)s (%(component)s) filed by %(changedBy)s [%(priority)s - %(severity)s]: %(shortDescription)s (https://bugs.kde.org/%(bugNumber)s)' + else: + template = 'Bug %(bugNumber)s in %(product)s (%(component)s) changed by %(changedBy)s [%(priority)s - %(severity)s - %(status)s]: %(shortDescription)s (https://bugs.kde.org/%(bugNumber)s)' else: - template = 'Bug %(bugNumber)s in %(product)s (%(component)s) changed by %(changedBy)s [%(priority)s - %(severity)s - %(status)s]:\n%(shortDescription)s\nhttps://bugs.kde.org/%(bugNumber)s' + if self.messageType == 'new': + template = 'New bug %(bugNumber)s in %(product)s (%(component)s) filed by %(changedBy)s [%(priority)s - %(severity)s]:\n%(shortDescription)s\nhttps://bugs.kde.org/%(bugNumber)s' + else: + template = 'Bug %(bugNumber)s in %(product)s (%(component)s) changed by %(changedBy)s [%(priority)s - %(severity)s - %(status)s]:\n%(shortDescription)s\nhttps://bugs.kde.org/%(bugNumber)s' return template % self.__dict__ # Load our configuration -configDefaults = {'product': '.*', 'assignee': '.*', 'priority': '.*', 'severity': '.*'} +configDefaults = { + 'product': '.*', + 'assignee': '.*', + 'priority': '.*', + 'severity': '.*', + 'onlynew': False, + 'compact': False +} config = configparser.SafeConfigParser(configDefaults) config.read(sys.argv[1]) # Read the email in emailParser = email.parser.Parser() email = emailParser.parse(sys.stdin) -# Ensure it is a CIA.vc formatted mail +# Ensure it is a Bugzilla formatted mail? if not ('X-Bugzilla-URL' in email and email['X-Bugzilla-URL'] == "http://bugs.kde.org/"): exit(0) # Parse the message we received from KDE Bugzilla (bugs.kde.org) message = BugzillaMessage(email) +# Establish a connection to Irker +connection = socket.socket(socket.AF_INET, socket.SOCK_STREAM) +connection.connect(("localhost", 6659)) + # Determine the channels we want to notify channels = [] for sectionName in config.sections(): @@ -74,6 +91,8 @@ assigneeEmail = re.compile( config.get(sectionName, 'assignee') ) priorityLevel = re.compile( config.get(sectionName, 'priority') ) severityLevel = re.compile( config.get(sectionName, 'severity') ) + messageType = config.get(sectionName, 'messageType').split(',') + compact = config.getboolean(sectionName, 'compact') except: continue @@ -92,12 +111,15 @@ if not severityLevel.match(message.severity): continue + if message.messageType not in messageType + continue + + # It's time to send the message, but make first let's make sure we don't spam the same channel twice... channelName = config.get(sectionName, 'channel') if channelName not in channels: + # Mark this channel as having received a notification channels.append(channelName) -# Convert our information into what Irker needs, and send it to Irker -content = json.dumps({"to": channels, "privmsg": message.summary()}) + "\n" -connection = socket.socket(socket.AF_INET, socket.SOCK_STREAM) -connection.connect(("localhost", 6659)) -connection.sendall(content.encode('utf-8')) + # Notify the channel + content = json.dumps({"to": [channelName], "privmsg": message.summary(compact)}) + "\n" + connection.sendall(content.encode('utf-8')) diff --git a/bugzilla/notifications.cfg b/bugzilla/notifications.cfg --- a/bugzilla/notifications.cfg +++ b/bugzilla/notifications.cfg @@ -4,3 +4,9 @@ [kdevelop] product=kdevelop channel=irc://chat.freenode.net/kdevelop + +[krita] +product=krita +channel=irc://chat.freenode.net/krita +messagetype=New|NeedInfo +compact=True