Skip to content

Commit

Permalink
Merge branch 'irc' of git://github.com/kzys/buildbot into irc-stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
Dustin J. Mitchell committed Oct 23, 2009
2 parents db55e15 + 1d591e9 commit 3c372f4
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 29 deletions.
80 changes: 52 additions & 28 deletions buildbot/status/words.py
Expand Up @@ -306,56 +306,64 @@ def buildStarted(self, builderName, build):

self.send(r)

results_descriptions = {
SUCCESS: "Success",
WARNINGS: "Warnings",
FAILURE: "Failure",
EXCEPTION: "Exception",
}

def buildFinished(self, builderName, build, results):
builder = build.getBuilder()

results_descriptions = {
SUCCESS: "Success",
WARNINGS: "Warnings",
FAILURE: "Failure",
EXCEPTION: "Exception",
}

# only notify about builders we are interested in
log.msg('[Contact] builder %r in category %s finished' % (builder, builder.category))

if (self.channel.categories != None and
builder.category not in self.channel.categories):
return

results = build.getResults()
if not self.notify_for_finished(build):
return

r = "build #%d of %s is complete: %s" % \
(build.getNumber(),
builder.getName(),
results_descriptions.get(results, "??"))
self.results_descriptions.get(build.getResults(), "??"))
r += " [%s]" % " ".join(build.getText())
buildurl = self.channel.status.getURLForThing(build)
if buildurl:
r += " Build details are at %s" % buildurl

if self.notify_for('finished') or self.notify_for(lower(results_descriptions.get(results))):
self.send(r)
return
if self.channel.showBlameList and build.getResults() != SUCCESS and len(build.changes) != 0:
r += ' blamelist: ' + ', '.join([c.who for c in build.changes])

self.send(r)

def notify_for_finished(self, build):
results = build.getResults()

if self.notify_for('finished'):
return True

if self.notify_for(lower(self.results_descriptions.get(results))):
return True

prevBuild = build.getPreviousBuild()
if prevBuild:
prevResult = prevBuild.getResults()

required_notification_control_string = join((lower(results_descriptions.get(prevResult)), \
required_notification_control_string = join((lower(self.results_descriptions.get(prevResult)), \
'To', \
capitalize(results_descriptions.get(results))), \
capitalize(self.results_descriptions.get(results))), \
'')

if (self.notify_for(required_notification_control_string)):
self.send(r)
return True

return False

def watchedBuildFinished(self, b):
results = {SUCCESS: "Success",
WARNINGS: "Warnings",
FAILURE: "Failure",
EXCEPTION: "Exception",
}

# only notify about builders we are interested in
builder = b.getBuilder()
Expand All @@ -368,7 +376,7 @@ def watchedBuildFinished(self, b):
r = "Hey! build %s #%d is complete: %s" % \
(b.getBuilder().getName(),
b.getNumber(),
results.get(b.getResults(), "??"))
self.results_descriptions.get(b.getResults(), "??"))
r += " [%s]" % " ".join(b.getText())
self.send(r)
buildurl = self.channel.status.getURLForThing(b)
Expand Down Expand Up @@ -580,14 +588,15 @@ def __init__(self, channel, dest):
self.dest = dest

def describeUser(self, user):
if self.dest[0] == "#":
if self.dest[0] == '#':
return "IRC user <%s> on channel %s" % (user, self.dest)
return "IRC user <%s> (privmsg)" % user

# userJoined(self, user, channel)

def send(self, message):
self.channel.msg(self.dest, message.encode("ascii", "replace"))
self.channel.msgOrNotice(self.dest, message.encode("ascii", "replace"))

def act(self, action):
self.channel.me(self.dest, action.encode("ascii", "replace"))

Expand Down Expand Up @@ -662,7 +671,7 @@ class IrcStatusBot(irc.IRCClient):
implements(IChannel)
contactClass = IRCContact

def __init__(self, nickname, password, channels, status, categories, notify_events):
def __init__(self, nickname, password, channels, status, categories, notify_events, noticeOnChannel = False, showBlameList = False):
"""
@type nickname: string
@param nickname: the nickname by which this bot should be known
Expand All @@ -683,6 +692,14 @@ def __init__(self, nickname, password, channels, status, categories, notify_even
self.counter = 0
self.hasQuit = 0
self.contacts = {}
self.noticeOnChannel = noticeOnChannel
self.showBlameList = showBlameList

def msgOrNotice(self, dest, message):
if self.noticeOnChannel and dest[0] == '#':
self.notice(dest, message)
else:
self.msg(dest, message)

def addContact(self, name, contact):
self.contacts[name] = contact
Expand Down Expand Up @@ -777,14 +794,16 @@ class IrcStatusFactory(ThrottledClientFactory):
shuttingDown = False
p = None

def __init__(self, nickname, password, channels, categories, notify_events):
def __init__(self, nickname, password, channels, categories, notify_events, noticeOnChannel = False, showBlameList = False):
#ThrottledClientFactory.__init__(self) # doesn't exist
self.status = None
self.nickname = nickname
self.password = password
self.channels = channels
self.categories = categories
self.notify_events = notify_events
self.noticeOnChannel = noticeOnChannel
self.showBlameList = showBlameList

def __getstate__(self):
d = self.__dict__.copy()
Expand All @@ -799,7 +818,9 @@ def shutdown(self):
def buildProtocol(self, address):
p = self.protocol(self.nickname, self.password,
self.channels, self.status,
self.categories, self.notify_events)
self.categories, self.notify_events,
noticeOnChannel = self.noticeOnChannel,
showBlameList = self.showBlameList)
p.factory = self
p.status = self.status
p.control = self.control
Expand Down Expand Up @@ -832,7 +853,8 @@ class IRC(base.StatusReceiverMultiService):
"categories"]

def __init__(self, host, nick, channels, port=6667, allowForce=True,
categories=None, password=None, notify_events={}):
categories=None, password=None, notify_events={},
noticeOnChannel = False, showBlameList = True):
base.StatusReceiverMultiService.__init__(self)

assert allowForce in (True, False) # TODO: implement others
Expand All @@ -848,7 +870,9 @@ def __init__(self, host, nick, channels, port=6667, allowForce=True,
self.notify_events = notify_events
log.msg('Notify events %s' % notify_events)
self.f = IrcStatusFactory(self.nick, self.password,
self.channels, self.categories, self.notify_events)
self.channels, self.categories, self.notify_events,
noticeOnChannel = noticeOnChannel,
showBlameList = showBlameList)
c = internet.TCPClient(self.host, self.port, self.f)
c.setServiceParent(self)

Expand Down
36 changes: 35 additions & 1 deletion buildbot/test/test_status.py
Expand Up @@ -1338,8 +1338,10 @@ def test_notification_failed(self):
self.failUnlessEqual(irc.message, "", "No started notification with notify_events=['failed']")

irc.message = ""
irc.channel.showBlameList = True
irc.buildFinished(my_builder.getName(), my_build, None)
self.failUnlessEqual(irc.message, "build #862 of builder834 is complete: Failure [step1 step2] Build details are at http://myserver/mypath?build=765", "Finish notification generated on failure with notify_events=['failed']")
self.failUnlessEqual(irc.message, "build #862 of builder834 is complete: Failure [step1 step2] Build details are at http://myserver/mypath?build=765 blamelist: author1", "Finish notification generated on failure with notify_events=['failed']")
irc.channel.showBlameList = False

irc.message = ""
my_build.results = builder.SUCCESS
Expand Down Expand Up @@ -1370,6 +1372,12 @@ def test_notification_exception(self):
irc.buildFinished(my_builder.getName(), my_build, None)
self.failUnlessEqual(irc.message, "build #862 of builder834 is complete: Exception [step1 step2] Build details are at http://myserver/mypath?build=765", "Finish notification generated on failure with notify_events=['exception']")

irc.message = ""
irc.channel.showBlameList = True
irc.buildFinished(my_builder.getName(), my_build, None)
self.failUnlessEqual(irc.message, "build #862 of builder834 is complete: Exception [step1 step2] Build details are at http://myserver/mypath?build=765 blamelist: author1", "Finish notification generated on failure with notify_events=['exception']")
irc.channel.showBlameList = False

irc.message = ""
my_build.results = builder.SUCCESS
irc.buildFinished(my_builder.getName(), my_build, None)
Expand Down Expand Up @@ -1609,6 +1617,7 @@ class MyChannel:

def __init__(self, notify_events = {}):
self.notify_events = notify_events
self.showBlameList = False

class MyContact(words.Contact):
message = ""
Expand All @@ -1626,6 +1635,31 @@ def unsubscribe_from_build_events(self):
def send(self, msg):
self.message += msg

class MyIrcStatusBot(words.IrcStatusBot):
def msg(self, dest, message):
self.message = ['msg', dest, message]

def notice(self, dest, message):
self.message = ['notice', dest, message]

class IrcStatusBotTester(unittest.TestCase):
def testMsgOrNotice(self):
channel = MyIrcStatusBot('alice', 'pa55w0od', ['#here'],
builder.SUCCESS, None, {})
channel.msgOrNotice('bob', 'hello')
self.failUnlessEqual(channel.message, ['msg', 'bob', 'hello'])

channel.msgOrNotice('#here', 'hello')
self.failUnlessEqual(channel.message, ['msg', '#here', 'hello'])

channel.noticeOnChannel = True

channel.msgOrNotice('bob', 'hello')
self.failUnlessEqual(channel.message, ['msg', 'bob', 'hello'])

channel.msgOrNotice('#here', 'hello')
self.failUnlessEqual(channel.message, ['notice', '#here', 'hello'])

class StepStatistics(unittest.TestCase):
def testStepStatistics(self):
status = builder.BuildStatus(builder.BuilderStatus("test"), 123)
Expand Down

0 comments on commit 3c372f4

Please sign in to comment.