From df7b8d651cb90eabd3e8cab27feff80679c61588 Mon Sep 17 00:00:00 2001 From: Joseph Schorr Date: Fri, 18 Jul 2014 11:52:36 -0400 Subject: [PATCH] Fix bugs in the initial impl of the notification event and notification method libs. --- endpoints/notificationevent.py | 10 +++++----- endpoints/notificationmethod.py | 13 ++++++++++--- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/endpoints/notificationevent.py b/endpoints/notificationevent.py index c091a204c..215962fbd 100644 --- a/endpoints/notificationevent.py +++ b/endpoints/notificationevent.py @@ -54,11 +54,11 @@ class RepoPushEvent(NotificationEvent): return 'repo_push' def get_summary(self, notification_data): - return 'Repository %s updated' % (event_data['repository']) + return 'Repository %s updated' % (notification_data['event_data']['repository']) def get_message(self, notification_data): event_data = notification_data['event_data'] - if not event_data['tags']: + if not event_data.get('updated_tags', []): return '%s images pushed for repository %s (%s)' % (event_data['pushed_image_count'], event_data['repository'], event_data['homepage']) @@ -86,7 +86,7 @@ class BuildStartEvent(NotificationEvent): def event_name(cls): return 'build_start' - def get_sample_data(repository=None): + def get_sample_data(self, repository=None): pass @@ -95,7 +95,7 @@ class BuildSuccessEvent(NotificationEvent): def event_name(cls): return 'build_success' - def get_sample_data(repository=None): + def get_sample_data(self, repository=None): pass @@ -104,5 +104,5 @@ class BuildFailureEvent(NotificationEvent): def event_name(cls): return 'build_failure' - def get_sample_data(repository=None): + def get_sample_data(self, repository=None): pass diff --git a/endpoints/notificationmethod.py b/endpoints/notificationmethod.py index 011a6b010..a7fd7b87e 100644 --- a/endpoints/notificationmethod.py +++ b/endpoints/notificationmethod.py @@ -50,14 +50,20 @@ class QuayNotificationMethod(NotificationMethod): return 'quay_notification' def perform(self, notification, event_handler, notification_data): + config_data = json.loads(notification.config_json) repository_id = notification_data['repository_id'] repository = model.lookup_repository(repository_id) if not repository: # Probably deleted. return True - model.create_notification(event_handler.event_name(), - repository.namespace, metadata=notification_data['event_data']) + target_name = config_data['target']; + target = model.get_user(target_name) + if not target: + return False + + model.create_notification(event_handler.event_name(), target, + metadata=notification_data['event_data']) return True @@ -78,7 +84,8 @@ class EmailMethod(NotificationMethod): msg.html = event_handler.get_message(notification_data) try: - mail.send(msg) + with app.app_context(): + mail.send(msg) except Exception as ex: logger.exception('Email was unable to be sent: %s' % ex.message) return False