parent
0dce935c40
commit
03d4445a02
3 changed files with 206 additions and 9 deletions
|
@ -1,6 +1,7 @@
|
|||
import logging
|
||||
import time
|
||||
import json
|
||||
import re
|
||||
|
||||
from datetime import datetime
|
||||
from notificationhelper import build_event_data
|
||||
|
@ -138,7 +139,28 @@ class VulnerabilityFoundEvent(NotificationEvent):
|
|||
', '.join(event_data['tags']))
|
||||
|
||||
|
||||
class BuildQueueEvent(NotificationEvent):
|
||||
class BaseBuildEvent(NotificationEvent):
|
||||
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
|
||||
if ref_regex is None:
|
||||
return True
|
||||
|
||||
# Lookup the ref. If none, this is a non-git build and we should not fire the event.
|
||||
ref = event_data.get('trigger_metadata', {}).get('ref', None)
|
||||
if ref is None:
|
||||
return False
|
||||
|
||||
# Try parsing the regex string as a regular expression. If we fail, we fail to fire
|
||||
# the event.
|
||||
try:
|
||||
return bool(re.compile(str(ref_regex)).match(ref))
|
||||
except Exception:
|
||||
logger.warning('Regular expression error for build event filter: %s', ref_regex)
|
||||
return False
|
||||
|
||||
|
||||
class BuildQueueEvent(BaseBuildEvent):
|
||||
@classmethod
|
||||
def event_name(cls):
|
||||
return 'build_queued'
|
||||
|
@ -177,7 +199,7 @@ class BuildQueueEvent(NotificationEvent):
|
|||
return 'Build queued ' + _build_summary(event_data)
|
||||
|
||||
|
||||
class BuildStartEvent(NotificationEvent):
|
||||
class BuildStartEvent(BaseBuildEvent):
|
||||
@classmethod
|
||||
def event_name(cls):
|
||||
return 'build_start'
|
||||
|
@ -205,7 +227,7 @@ class BuildStartEvent(NotificationEvent):
|
|||
return 'Build started ' + _build_summary(event_data)
|
||||
|
||||
|
||||
class BuildSuccessEvent(NotificationEvent):
|
||||
class BuildSuccessEvent(BaseBuildEvent):
|
||||
@classmethod
|
||||
def event_name(cls):
|
||||
return 'build_success'
|
||||
|
@ -234,7 +256,7 @@ class BuildSuccessEvent(NotificationEvent):
|
|||
return 'Build succeeded ' + _build_summary(event_data)
|
||||
|
||||
|
||||
class BuildFailureEvent(NotificationEvent):
|
||||
class BuildFailureEvent(BaseBuildEvent):
|
||||
@classmethod
|
||||
def event_name(cls):
|
||||
return 'build_failure'
|
||||
|
|
Reference in a new issue