Fix bugs in the initial impl of the notification event and notification method libs.
This commit is contained in:
parent
8d7493cb86
commit
df7b8d651c
2 changed files with 15 additions and 8 deletions
|
@ -54,11 +54,11 @@ class RepoPushEvent(NotificationEvent):
|
||||||
return 'repo_push'
|
return 'repo_push'
|
||||||
|
|
||||||
def get_summary(self, notification_data):
|
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):
|
def get_message(self, notification_data):
|
||||||
event_data = notification_data['event_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'],
|
return '%s images pushed for repository %s (%s)' % (event_data['pushed_image_count'],
|
||||||
event_data['repository'], event_data['homepage'])
|
event_data['repository'], event_data['homepage'])
|
||||||
|
|
||||||
|
@ -86,7 +86,7 @@ class BuildStartEvent(NotificationEvent):
|
||||||
def event_name(cls):
|
def event_name(cls):
|
||||||
return 'build_start'
|
return 'build_start'
|
||||||
|
|
||||||
def get_sample_data(repository=None):
|
def get_sample_data(self, repository=None):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
@ -95,7 +95,7 @@ class BuildSuccessEvent(NotificationEvent):
|
||||||
def event_name(cls):
|
def event_name(cls):
|
||||||
return 'build_success'
|
return 'build_success'
|
||||||
|
|
||||||
def get_sample_data(repository=None):
|
def get_sample_data(self, repository=None):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
@ -104,5 +104,5 @@ class BuildFailureEvent(NotificationEvent):
|
||||||
def event_name(cls):
|
def event_name(cls):
|
||||||
return 'build_failure'
|
return 'build_failure'
|
||||||
|
|
||||||
def get_sample_data(repository=None):
|
def get_sample_data(self, repository=None):
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -50,14 +50,20 @@ class QuayNotificationMethod(NotificationMethod):
|
||||||
return 'quay_notification'
|
return 'quay_notification'
|
||||||
|
|
||||||
def perform(self, notification, event_handler, notification_data):
|
def perform(self, notification, event_handler, notification_data):
|
||||||
|
config_data = json.loads(notification.config_json)
|
||||||
repository_id = notification_data['repository_id']
|
repository_id = notification_data['repository_id']
|
||||||
repository = model.lookup_repository(repository_id)
|
repository = model.lookup_repository(repository_id)
|
||||||
if not repository:
|
if not repository:
|
||||||
# Probably deleted.
|
# Probably deleted.
|
||||||
return True
|
return True
|
||||||
|
|
||||||
model.create_notification(event_handler.event_name(),
|
target_name = config_data['target'];
|
||||||
repository.namespace, metadata=notification_data['event_data'])
|
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
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
@ -78,7 +84,8 @@ class EmailMethod(NotificationMethod):
|
||||||
msg.html = event_handler.get_message(notification_data)
|
msg.html = event_handler.get_message(notification_data)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
mail.send(msg)
|
with app.app_context():
|
||||||
|
mail.send(msg)
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
logger.exception('Email was unable to be sent: %s' % ex.message)
|
logger.exception('Email was unable to be sent: %s' % ex.message)
|
||||||
return False
|
return False
|
||||||
|
|
Reference in a new issue