From 575b062cbd46957d31dd21fa94bacd1d507dbbee Mon Sep 17 00:00:00 2001 From: Ricardo Carrillo Cruz Date: Sun, 9 Mar 2014 19:51:57 +0000 Subject: [PATCH] Add support for notification of releases on IRC Closes-Bug: #1227985 Change-Id: I9b80b465d9d6b0e2793286cc8229b82b4389a08d --- gerritbot/bot.py | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/gerritbot/bot.py b/gerritbot/bot.py index 93a4cca..8027b8c 100755 --- a/gerritbot/bot.py +++ b/gerritbot/bot.py @@ -50,6 +50,7 @@ import daemon import irc.bot import logging.config import os +import re import ssl import sys import threading @@ -154,6 +155,20 @@ class Gerrit(threading.Thread): self.log.info('Compiled Message %s: %s' % (channel, msg)) self.ircbot.send(channel, msg) + def ref_updated(self, channel, data): + refName = data['refUpdate']['refName'] + m = re.match(r'(refs/tags)/(.*)', refName) + + if m: + tag = m.group(2) + msg = '%s tagged project %s with %s' % ( + data['submitter']['username'], + data['refUpdate']['project'], + tag + ) + self.log.info('Compiled Message %s: %s' % (channel, msg)) + self.ircbot.send(channel, msg) + def comment_added(self, channel, data): msg = 'A comment has been added to a proposed change to %s: %s %s' % ( data['change']['project'], @@ -213,12 +228,15 @@ class Gerrit(threading.Thread): def _read(self, data): try: - channel_set = (self.channel_config.projects.get( - data['change']['project'], set()) & - self.channel_config.events.get( - data['type'], set()) & - self.channel_config.branches.get( - data['change']['branch'], set())) + if data['type'] == 'ref-updated': + channel_set = self.channel_config.events.get('ref-updated') + else: + channel_set = (self.channel_config.projects.get( + data['change']['project'], set()) & + self.channel_config.events.get( + data['type'], set()) & + self.channel_config.branches.get( + data['change']['branch'], set())) except KeyError: # The data we care about was not present, no channels want # this event. @@ -232,6 +250,8 @@ class Gerrit(threading.Thread): self.patchset_created(channel, data) elif data['type'] == 'change-merged': self.change_merged(channel, data) + elif data['type'] == 'ref-updated': + self.ref_updated(channel, data) def run(self): while True: