Fix bugs in the initial impl of the notification event and notification method libs.

This commit is contained in:
Joseph Schorr 2014-07-18 11:52:36 -04:00
parent 8d7493cb86
commit df7b8d651c
2 changed files with 15 additions and 8 deletions

View file

@ -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

View file

@ -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