Change notificationworker to use a data interface

This commit is contained in:
Joseph Schorr 2017-07-12 15:50:47 +03:00
parent 8ec198228c
commit b6f1782642
10 changed files with 149 additions and 56 deletions

View file

@ -56,7 +56,7 @@ class NotificationMethod(object):
"""
Performs the notification method.
notification_obj: The noticication record itself.
notification_obj: The noticication namedtuple.
event_handler: The NotificationEvent handler.
notification_data: The dict of notification data placed in the queue.
"""
@ -122,7 +122,7 @@ class QuayNotificationMethod(NotificationMethod):
return
# Lookup the target user or team to which we'll send the notification.
config_data = json.loads(notification_obj.config_json)
config_data = notification_obj.method_config_dict
status, err_message, target_users = self.find_targets(repository, config_data)
if not status:
raise NotificationMethodPerformException(err_message)
@ -151,7 +151,7 @@ class EmailMethod(NotificationMethod):
'notifications for this repository')
def perform(self, notification_obj, event_handler, notification_data):
config_data = json.loads(notification_obj.config_json)
config_data = notification_obj.method_config_dict
email = config_data.get('email', '')
if not email:
return
@ -179,7 +179,7 @@ class WebhookMethod(NotificationMethod):
raise CannotValidateNotificationMethodException('Missing webhook URL')
def perform(self, notification_obj, event_handler, notification_data):
config_data = json.loads(notification_obj.config_json)
config_data = notification_obj.method_config_dict
url = config_data.get('url', '')
if not url:
return
@ -216,7 +216,7 @@ class FlowdockMethod(NotificationMethod):
raise CannotValidateNotificationMethodException('Missing Flowdock API Token')
def perform(self, notification_obj, event_handler, notification_data):
config_data = json.loads(notification_obj.config_json)
config_data = notification_obj.method_config_dict
token = config_data.get('flow_api_token', '')
if not token:
return
@ -270,8 +270,7 @@ class HipchatMethod(NotificationMethod):
raise CannotValidateNotificationMethodException('Missing Hipchat Room ID')
def perform(self, notification_obj, event_handler, notification_data):
config_data = json.loads(notification_obj.config_json)
config_data = notification_obj.method_config_dict
token = config_data.get('notification_token', '')
room_id = config_data.get('room_id', '')
@ -385,8 +384,7 @@ class SlackMethod(NotificationMethod):
return adjust_tags(message)
def perform(self, notification_obj, event_handler, notification_data):
config_data = json.loads(notification_obj.config_json)
config_data = notification_obj.method_config_dict
url = config_data.get('url', '')
if not url:
return