diff --git a/lyrebird_bugit/event_handler.py b/lyrebird_bugit/event_handler.py index 44c498b..4458350 100644 --- a/lyrebird_bugit/event_handler.py +++ b/lyrebird_bugit/event_handler.py @@ -1,7 +1,9 @@ import lyrebird +from . import template_loader from uuid import uuid4 from collections import OrderedDict from lyrebird import get_logger +from lyrebird import application logger = get_logger() @@ -57,3 +59,10 @@ def on_upload_files(msg): 'name': item['upload_file']['name'], 'path': item['upload_file']['path']} lyrebird.emit('attachments') + + +def on_notice(msg): + conf_autoissue = application.config.get('autoissue', False) + if not conf_autoissue: + return + template_loader.notice_handler(msg) diff --git a/lyrebird_bugit/manifest.py b/lyrebird_bugit/manifest.py index 0d0997d..e3c0e8b 100644 --- a/lyrebird_bugit/manifest.py +++ b/lyrebird_bugit/manifest.py @@ -21,6 +21,7 @@ ('ios.device', event_handler.on_ios_device), ('android.screenshot', event_handler.on_android_screenshot), ('ios.screenshot', event_handler.on_ios_screenshot), - ('upload_files', event_handler.on_upload_files) + ('upload_files', event_handler.on_upload_files), + ('notice', event_handler.on_notice) ] ) diff --git a/lyrebird_bugit/template_loader.py b/lyrebird_bugit/template_loader.py index cc3ae02..8dd3bd2 100644 --- a/lyrebird_bugit/template_loader.py +++ b/lyrebird_bugit/template_loader.py @@ -24,7 +24,7 @@ def get_workspace(): return metadata_dir -def get_default_template(): +def get_default_template_path(): bugit_workspace = application.config.get('bugit.workspace', '') bugit_default_template = application.config.get('bugit.default_template', '') template_path = Path(bugit_workspace + bugit_default_template) @@ -34,11 +34,11 @@ def get_default_template(): def template_list(): template_list = [] - default_template = get_default_template() + default_template_path = get_default_template_path() for template_file in get_workspace().iterdir(): if not template_file.name.endswith('.py'): continue - if default_template and template_file != default_template: + if default_template_path and template_file != default_template_path: continue try: logger.debug(f'Load template {template_file}') @@ -71,3 +71,23 @@ def template_check(template): def get_template(file_path): template = imp.load_source(Path(file_path).stem, str(file_path)) return template + + +def notice_handler(msg): + # Filter out messages with invalid types + if not isinstance(msg, dict): + return + + # Filter out messages from unconfigured extensions + checker_switch = application.config.get('autoissue.checker.switch', {}) + sender_file = msg.get('sender', {}).get('file', '') + if sender_file not in checker_switch: + return + + default_template_path = get_default_template_path() + if default_template_path is None: + logger.error(f'Init Auto Issue Server Failed. Template path is configured incorrectly: {default_template_path}') + return + + template = get_template(default_template_path) + template.AutoIssue().auto_issue_handler(msg)