summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeffrey C. Ollie <jeff@ocjtech.us>2008-12-15 16:20:41 -0600
committerJeffrey C. Ollie <jeff@ocjtech.us>2008-12-15 16:20:41 -0600
commit3219dea702997b1fccf80a1ba8d5c799ed3580d0 (patch)
treed647b684a10162f400966f2b18adbeb6eed947a2
parent41a6f66811c18cdf3c17f3bd374d5a8a1f580ba8 (diff)
downloadcvsmessaging-3219dea702997b1fccf80a1ba8d5c799ed3580d0.tar.gz
cvsmessaging-3219dea702997b1fccf80a1ba8d5c799ed3580d0.tar.xz
cvsmessaging-3219dea702997b1fccf80a1ba8d5c799ed3580d0.zip
Move the smarts for picking recipients.
This should be done in the consumer, which will save a number of invocations of the producer and save the user time and the number of times that diffs need to be produced.
-rw-r--r--README2
-rwxr-xr-xloginfo-consumer56
-rwxr-xr-xloginfo-producer6
3 files changed, 48 insertions, 16 deletions
diff --git a/README b/README
index 8bd859f..c021545 100644
--- a/README
+++ b/README
@@ -18,7 +18,7 @@ Really basic instructions:
edit "loginfo" and add this line
- ALL /path/to/loginfo-producer
+ ALL /path/to/loginfo-producer %{sVv}
cvs ci -m "Add loginfo hook"
diff --git a/loginfo-consumer b/loginfo-consumer
index edab648..15ca8cd 100755
--- a/loginfo-consumer
+++ b/loginfo-consumer
@@ -65,8 +65,44 @@ def append_package_owner_email(directory, recipients):
package_match = package_re.match(directory)
if package_match and package_match.group(1):
- recipients.append('%s-owner@fedoraproject.org' % package_match.group(1))
-
+ recipients.add('%s-owner@fedoraproject.org' % package_match.group(1))
+
+
+directory_based_notifications = [(re.compile(r'^rpms'), [append_package_owner_email,
+ 'cvsextras@fedoraproject.org']),
+ (re.compile(r'^devel'), [append_package_owner_email,
+ 'cvsextras@fedoraproject.org']),
+ (re.compile(r'^common'), ['cvsextras@fedoraproject.org',
+ 'jkeating@redhat.com']),
+ (re.compile(r'^owners'), ['cvsextras@fedoraproject.org',
+ 'cvsadmin-menbers@fedoraproject.org']),
+ (re.compile(r'^comps'), ['cvsextras@fedoraproject.org',
+ 'katzj@redhat.com',
+ 'notting@redhat.com',
+ 'jkeating@redhat.com'])]
+
+message_based_notifications = [(re.compile(r'docs'), ['relnotes@fedoraproject.org'])]
+
+def process_notifications(directory, message, recipients, notifications):
+ for notification in notifications:
+ if isinstance(notification, basestring):
+ recipients.add(notification)
+ elif callable(notification):
+ notification(directory, message, recipients)
+
+def compute_directory_based_notifications(directory, message, recipients):
+ for pattern, notifications in directory_based_notifications:
+ match = pattern.match(directory)
+ if match:
+ process_notifications(directory, message, recipients, notifications)
+
+
+def compute_message_based_notifications(directory, message, email_recipient_set):
+ for pattern, notifications in message_based_notifications:
+ match = pattern.search(message)
+ if match:
+ process_notifications(directory, message, recipients, notifications)
+
host = '127.0.0.1'
port = 5672
@@ -119,13 +155,15 @@ while True:
# build the list of recipients
- email_recipients = []
- for notification_element in root_element.xpath('/loginfo/notifications/notification'):
- notification = notification_element.text
- if notification == u'%%OWNER%%':
- append_package_owner_email(directory, email_recipients)
- else:
- email_recipients.append(notification)
+ recipients = set()
+ compute_directory_based_notifications(directory, message, recipients)
+ compute_message_based_notifications(directory, message, recipients)
+
+ if len(recipients) == 0:
+ recipients.add('admin@fedoraproject.org')
+
+ email_recipients = list(recipients)
+ email_recipients.sort()
# Build the email object
diff --git a/loginfo-producer b/loginfo-producer
index e4c6b8b..f927168 100755
--- a/loginfo-producer
+++ b/loginfo-producer
@@ -60,12 +60,6 @@ cvsroot = os.environ['CVSROOT']
cvsroot_element = etree.SubElement(root_element, 'cvsroot')
cvsroot_element.text = cvsroot
-notifications_element = etree.SubElement(root_element, 'notifications')
-
-for arg in sys.argv[2:]:
- notification_element = etree.SubElement(notifications_element, 'notification')
- notification_element.text = arg
-
directory_re = re.compile(r'^Update of %s/(.*)$' % (cvsroot,), re.M)
message = sys.stdin.read().decode('utf-8')