Allow gerritbot to filter notifications by branch

Fixes bug 878187 by introducing a "branches" config parameter which,
when set, will make gerritbot filter notifications that do not apply to
the specified branch(es). Untested, so deploy with extra care.

Change-Id: I7ac537bb805c9ea0aca5fea89017a3dcc52867c3
This commit is contained in:
Thierry Carrez
2011-10-20 16:33:48 +02:00
parent 7874c0cec0
commit a4de272af0

View File

@@ -15,6 +15,7 @@ key=/path/to/id_rsa
host=review.example.com
port=29418
events=patchset-created, change-merged
branches=master
"""
import ircbot
@@ -55,10 +56,12 @@ class GerritBot(ircbot.SingleServerIRCBot):
time.sleep(0.5)
class Gerrit(threading.Thread):
def __init__(self, ircbot, events, username, keyfile, server, port=29418):
def __init__(self, ircbot, events, branches,
username, keyfile, server, port=29418):
threading.Thread.__init__(self)
self.ircbot = ircbot
self.events = events
self.branches = branches
self.username = username
self.keyfile = keyfile
self.server = server
@@ -150,6 +153,9 @@ class Gerrit(threading.Thread):
def _read(self):
l = self.proc.stdout.readline()
data = json.loads(l)
# If branches is specified, ignore notifications for other branches
if self.branches and data['change']['branch'] not in self.branches:
return
if data['type'] == 'comment-added':
self.comment_added(data)
elif data['type'] == 'patchset-created':
@@ -193,6 +199,7 @@ def _main():
config.getint('ircbot', 'port'))
g = Gerrit(bot,
config.get('gerrit', 'events'),
config.get('gerrit', 'branches'),
config.get('gerrit', 'user'),
config.get('gerrit', 'key'),
config.get('gerrit', 'host'),