diff --git a/README.md b/README.md index 9a269da..d1b7945 100644 --- a/README.md +++ b/README.md @@ -66,6 +66,10 @@ BugIt支持自动填充Lyrebird运行过程中抓取到的数据信息。 ![BugIt获取报警信息](./image/bugit_alert.gif) +此外,还支持针对指定检查器的报警进行自动开Bug。 + +通过配置可以指定检查器,BugIt会将这些检查器的报警信息送入配置指定的脚本内,在脚本内自定义对报警信息的处理,即可实现Bug的自动上报功能。 + ## 缓存功能 按下[Commond]+[s]键,会将Bug相关字段信息进行存储。 diff --git a/lyrebird_bugit/apis.py b/lyrebird_bugit/apis.py index ffcd658..1e821b3 100644 --- a/lyrebird_bugit/apis.py +++ b/lyrebird_bugit/apis.py @@ -24,6 +24,7 @@ def template(): Get all template list, all draft list, last selected template and last selected draft ''' templates = template_loader.template_list() + default_template = template_loader.get_default_template_path() draft_version = cache.check_draft_version() if draft_version < cache.DRAFT_VERSION_V_1_12_4: @@ -32,6 +33,9 @@ def template(): cache.update_all_draft_file(templates) last_selected_template = cache.get_selected_template() + if not last_selected_template and default_template: + last_selected_template = str(default_template) + selected_template_index = None for index, template in enumerate(templates): if template['path'] == last_selected_template: diff --git a/lyrebird_bugit/event_handler.py b/lyrebird_bugit/event_handler.py index 44c498b..80f0092 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): + sender_file = msg.get('sender', {}).get('file', '') + autoissue_checker = application.config.get('event.notice.autoissue.checker', []) + if sender_file in autoissue_checker: + 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 864bd2c..f26b403 100644 --- a/lyrebird_bugit/template_loader.py +++ b/lyrebird_bugit/template_loader.py @@ -8,6 +8,8 @@ logger = get_logger() +autoissue_ready = None +last_template = None def get_workspace(): bugit_workspace = application.config.get('bugit.workspace') @@ -24,6 +26,18 @@ def get_workspace(): return metadata_dir +def get_default_template_path(): + bugit_workspace = application.config.get('bugit.workspace') + if not bugit_workspace: + return + + bugit_default_template = application.config.get('bugit.default_template') + if not bugit_default_template: + return + + return Path(bugit_workspace) / Path(bugit_default_template) + + def template_list(): template_list = [] for template_file in get_workspace().iterdir(): @@ -57,6 +71,49 @@ def template_check(template): template.submit), "BugIt template should have submit function" +def default_template_check(template_path): + global autoissue_ready + + if not template_path: + logger.error('Default template path is not configured.') + autoissue_ready = False + return + + if not template_path.exists(): + logger.error('Default template path is not existed.') + autoissue_ready = False + return + + template = get_template(template_path) + if not (hasattr(template, 'auto_issue') and callable(template.auto_issue)): + logger.error('Default template should have auto_issue function.') + autoissue_ready = False + return + + autoissue_ready = True + + def get_template(file_path): - template = imp.load_source(Path(file_path).stem, str(file_path)) - return template + global last_template + + if not last_template or last_template.__file__ != str(file_path): + last_template = imp.load_source(Path(file_path).stem, str(file_path)) + + return last_template + + +def notice_handler(msg): + default_template_path = get_default_template_path() + + if autoissue_ready is None: + default_template_check(default_template_path) + + if autoissue_ready == False: + return + + # Filter out messages with invalid types + if not isinstance(msg, dict): + return + + template = get_template(default_template_path) + template.auto_issue(msg) diff --git a/setup.py b/setup.py index 220ace1..751c58b 100644 --- a/setup.py +++ b/setup.py @@ -8,7 +8,7 @@ setup( name='lyrebird-bugit', - version='1.14.2', + version='1.15.0', packages=['lyrebird_bugit'], url='https://github.com/Meituan-Dianping/lyrebird-bugit', author='HBQA',