Merge pull request #1859 from coreos-inc/notification-issue
Fix build notifications
This commit is contained in:
commit
2505de8720
2 changed files with 28 additions and 4 deletions
|
@ -61,13 +61,24 @@ class NotificationEvent(object):
|
|||
|
||||
@classmethod
|
||||
def get_event(cls, eventname):
|
||||
for subc in cls.__subclasses__():
|
||||
if subc.event_name() == eventname:
|
||||
return subc()
|
||||
found = NotificationEvent._get_event(cls, eventname)
|
||||
if found is not None:
|
||||
return found
|
||||
|
||||
raise InvalidNotificationEventException('Unable to find event: %s' % eventname)
|
||||
|
||||
|
||||
@staticmethod
|
||||
def _get_event(cls, eventname):
|
||||
for subc in cls.__subclasses__():
|
||||
if subc.event_name() is None:
|
||||
found = NotificationEvent._get_event(subc, eventname)
|
||||
if found is not None:
|
||||
return found
|
||||
elif subc.event_name() == eventname:
|
||||
return subc()
|
||||
|
||||
|
||||
class RepoPushEvent(NotificationEvent):
|
||||
@classmethod
|
||||
def event_name(cls):
|
||||
|
@ -140,6 +151,10 @@ class VulnerabilityFoundEvent(NotificationEvent):
|
|||
|
||||
|
||||
class BaseBuildEvent(NotificationEvent):
|
||||
@classmethod
|
||||
def event_name(cls):
|
||||
return None
|
||||
|
||||
def should_perform(self, event_data, notification_data):
|
||||
event_config = json.loads(notification_data.event_config_json)
|
||||
ref_regex = event_config.get('ref-regex') or None
|
||||
|
|
|
@ -1,8 +1,17 @@
|
|||
import unittest
|
||||
|
||||
from endpoints.notificationevent import BuildSuccessEvent
|
||||
from endpoints.notificationevent import BuildSuccessEvent, NotificationEvent
|
||||
from util.morecollections import AttrDict
|
||||
|
||||
class TestCreate(unittest.TestCase):
|
||||
def test_create_notifications(self):
|
||||
self.assertIsNotNone(NotificationEvent.get_event('repo_push'))
|
||||
self.assertIsNotNone(NotificationEvent.get_event('build_queued'))
|
||||
self.assertIsNotNone(NotificationEvent.get_event('build_success'))
|
||||
self.assertIsNotNone(NotificationEvent.get_event('build_failure'))
|
||||
self.assertIsNotNone(NotificationEvent.get_event('build_start'))
|
||||
|
||||
|
||||
class TestShouldPerform(unittest.TestCase):
|
||||
def test_build_nofilter(self):
|
||||
notification_data = AttrDict({
|
||||
|
|
Reference in a new issue