Add multi-project irc support to the bot
This commit adds support for multi-project/channel irc support to the bot. To do this you list multiple channels in the bot yaml and specify which projects get reported to that file. When a bug is encountered that targets the listed project the message will be reported. If 'all' is specified as a field under projects for a channel then all projects will be reported on that channel. Change-Id: Ic3dd76bad94213c7152c29a99c00ed23a2c01a31
This commit is contained in:
parent
ca59c67993
commit
6fd0cf7e65
@ -48,6 +48,9 @@ import time
|
|||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
import irc.bot
|
import irc.bot
|
||||||
|
from launchpadlib import launchpad
|
||||||
|
|
||||||
|
LPCACHEDIR = os.path.expanduser('~/.launchpadlib/cache')
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import daemon.pidlockfile
|
import daemon.pidlockfile
|
||||||
@ -107,6 +110,9 @@ class RecheckWatch(threading.Thread):
|
|||||||
self.connected = False
|
self.connected = False
|
||||||
self.commenting = commenting
|
self.commenting = commenting
|
||||||
self.key = key
|
self.key = key
|
||||||
|
self.lp = launchpad.Launchpad.login_anonymously('grabbing bugs',
|
||||||
|
'production',
|
||||||
|
LPCACHEDIR)
|
||||||
|
|
||||||
def new_error(self, channel, event):
|
def new_error(self, channel, event):
|
||||||
msg = '%s change: %s failed with an unrecognized error' % (
|
msg = '%s change: %s failed with an unrecognized error' % (
|
||||||
@ -116,13 +122,36 @@ class RecheckWatch(threading.Thread):
|
|||||||
def error_found(self, channel, event):
|
def error_found(self, channel, event):
|
||||||
msg = ('%s change: %s failed tempest because of: %s' % (
|
msg = ('%s change: %s failed tempest because of: %s' % (
|
||||||
event.project, event.url, event.bug_urls()))
|
event.project, event.url, event.bug_urls()))
|
||||||
|
display = False
|
||||||
|
for project in self._get_bug_projects(event.bugs):
|
||||||
|
if channel in self.channel_config.projects['all']:
|
||||||
|
display = True
|
||||||
|
break
|
||||||
|
elif project in self.channel_config.projects:
|
||||||
|
if channel in self.channel_config.projects[project]:
|
||||||
|
display = True
|
||||||
|
break
|
||||||
|
if display:
|
||||||
self.print_msg(channel, msg)
|
self.print_msg(channel, msg)
|
||||||
|
else:
|
||||||
|
LOG.info("Didn't leave a message on channel %s for %s because the "
|
||||||
|
"bug doesn't target an appropriate project" % (
|
||||||
|
channel, event.url))
|
||||||
|
|
||||||
def print_msg(self, channel, msg):
|
def print_msg(self, channel, msg):
|
||||||
LOG.info('Compiled Message %s: %s' % (channel, msg))
|
LOG.info('Compiled Message %s: %s' % (channel, msg))
|
||||||
if self.ircbot:
|
if self.ircbot:
|
||||||
self.ircbot.send(channel, msg)
|
self.ircbot.send(channel, msg)
|
||||||
|
|
||||||
|
def _get_bug_projects(self, bug_numbers):
|
||||||
|
projects = []
|
||||||
|
for bug in bug_numbers:
|
||||||
|
lp_bug = self.lp.bugs[bug]
|
||||||
|
project = map(lambda x: (x.bug_target_name), lp_bug.bug_tasks)
|
||||||
|
for p in project:
|
||||||
|
projects.append(p)
|
||||||
|
return set(projects)
|
||||||
|
|
||||||
def _read(self, event=None, msg=""):
|
def _read(self, event=None, msg=""):
|
||||||
for channel in self.channel_config.channels:
|
for channel in self.channel_config.channels:
|
||||||
if msg:
|
if msg:
|
||||||
@ -178,6 +207,12 @@ class ChannelConfig(object):
|
|||||||
event_set = self.events.get(event, set())
|
event_set = self.events.get(event, set())
|
||||||
event_set.add(channel)
|
event_set.add(channel)
|
||||||
self.events[event] = event_set
|
self.events[event] = event_set
|
||||||
|
self.projects = {}
|
||||||
|
for channel, val in self.data.iteritems():
|
||||||
|
for project in val['projects']:
|
||||||
|
project_set = self.projects.get(project, set())
|
||||||
|
project_set.add(channel)
|
||||||
|
self.projects[project] = project_set
|
||||||
|
|
||||||
|
|
||||||
def get_options():
|
def get_options():
|
||||||
|
@ -1,4 +1,18 @@
|
|||||||
|
openstack-nova:
|
||||||
|
projects:
|
||||||
|
- nova
|
||||||
|
events:
|
||||||
|
- positive
|
||||||
|
|
||||||
|
openstack-glance:
|
||||||
|
projects:
|
||||||
|
- glance
|
||||||
|
events:
|
||||||
|
- positive
|
||||||
|
|
||||||
openstack-qa:
|
openstack-qa:
|
||||||
|
projects:
|
||||||
|
- all
|
||||||
events:
|
events:
|
||||||
- positive
|
- positive
|
||||||
- negative
|
- negative
|
||||||
|
Loading…
x
Reference in New Issue
Block a user