Skip to content

Instantly share code, notes, and snippets.

@mgedmin
Created June 5, 2012 13:59
Show Gist options
  • Save mgedmin/2875188 to your computer and use it in GitHub Desktop.
Save mgedmin/2875188 to your computer and use it in GitHub Desktop.
Patch to trac-bitten-slave to enable notifications on 1st success after failure, and hacky hacky IRC announcements
--- bitten/notify.py.orig 2010-10-21 00:00:00.000000000 -0400
+++ bitten/notify.py 2012-05-22 12:41:56.088838001 -0400
@@ -27,6 +27,10 @@
'notify_on_successful_build', 'false',
"""Notify if bitten build succeeds.""")
+ notify_on_success_after_failure = BoolOption('notification',
+ 'notify_on_successful_build_after_failure', 'false',
+ '''Notify if bitten build succeeds after a build failed.''')
+
def __init__(self):
self.log.debug('Initializing BittenNotify plugin')
@@ -47,6 +51,9 @@
if build.status == Build.FAILURE:
return self.notify_on_failure
elif build.status == Build.SUCCESS:
+ prev_build = Build.fetch(build.env, build.id-1)
+ if prev_build is not None and prev_build.status == Build.FAILURE:
+ return self.notify_on_success_after_failure
return self.notify_on_success
else:
return False
@@ -104,10 +111,21 @@
self.build.rev,
self.build.config)
NotifyEmail.notify(self, self.build.id, subject)
+ # One half of IRC notifications: write them to a file.
+ # The other half is Supybot's Tail plugin that watches that file.
+ try:
+ with open('/home/irc-bot/announcements', 'a') as f:
+ f.write('%s, %s: %s\n' % (self.get_author(), subject, self.build_link()))
+ except Exception, e:
+ self.log.exception("Failure writing announcement for build "
+ "%s: %s", build.id, e)
def get_recipients(self, resid):
to = [self.get_author()]
- cc = []
+ if self.config.has_option('notification', 'notify_cc'):
+ cc = self.config.get('notification', 'notify_cc').split(',')
+ else:
+ cc = []
return (to, cc)
def send(self, torcpts, ccrcpts):
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment