From 2762beae765438ec61bfe5558b2b9c1a086bdb60 Mon Sep 17 00:00:00 2001 From: ZhaoYangyang0403 Date: Thu, 14 Sep 2023 10:32:38 +0800 Subject: [PATCH 1/9] default template according to business --- lyrebird_bugit/apis.py | 4 ++++ lyrebird_bugit/template_loader.py | 12 ++++++++++++ 2 files changed, 16 insertions(+) diff --git a/lyrebird_bugit/apis.py b/lyrebird_bugit/apis.py index ffcd658..0d415bd 100644 --- a/lyrebird_bugit/apis.py +++ b/lyrebird_bugit/apis.py @@ -32,6 +32,10 @@ def template(): cache.update_all_draft_file(templates) last_selected_template = cache.get_selected_template() + if len(templates) == 1 and last_selected_template != templates[0]['path']: + last_selected_template = templates[0]['path'] + cache.selected_template(last_selected_template, None) + selected_template_index = None for index, template in enumerate(templates): if template['path'] == last_selected_template: diff --git a/lyrebird_bugit/template_loader.py b/lyrebird_bugit/template_loader.py index 864bd2c..b185773 100644 --- a/lyrebird_bugit/template_loader.py +++ b/lyrebird_bugit/template_loader.py @@ -24,11 +24,23 @@ def get_workspace(): return metadata_dir +def get_default_template(): + bugit_workspace = application.config.get('bugit.workspace', '') + bugit_template = application.config.get('bugit.template', '') + template_path = Path(bugit_workspace + bugit_template) + if bugit_workspace and bugit_template and template_path.exists(): + return template_path + return + + def template_list(): template_list = [] + default_template = get_default_template() for template_file in get_workspace().iterdir(): if not template_file.name.endswith('.py'): continue + if default_template and template_file != default_template: + continue try: logger.debug(f'Load template {template_file}') template = imp.load_source(template_file.stem, str(template_file)) From dc7e2a2412331e1d06a824f6b267619fa06008b9 Mon Sep 17 00:00:00 2001 From: ZhaoYangyang0403 Date: Mon, 18 Sep 2023 12:01:22 +0800 Subject: [PATCH 2/9] change name: bugit default template --- lyrebird_bugit/template_loader.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lyrebird_bugit/template_loader.py b/lyrebird_bugit/template_loader.py index b185773..958bfc8 100644 --- a/lyrebird_bugit/template_loader.py +++ b/lyrebird_bugit/template_loader.py @@ -26,9 +26,9 @@ def get_workspace(): def get_default_template(): bugit_workspace = application.config.get('bugit.workspace', '') - bugit_template = application.config.get('bugit.template', '') - template_path = Path(bugit_workspace + bugit_template) - if bugit_workspace and bugit_template and template_path.exists(): + bugit_default_template = application.config.get('bugit.default_template', '') + template_path = Path(bugit_workspace + bugit_default_template) + if bugit_workspace and bugit_default_template and template_path.exists(): return template_path return From 1ecf7fd771e4f4ed304333676ed60907f58b3319 Mon Sep 17 00:00:00 2001 From: ZhaoYangyang0403 Date: Mon, 18 Sep 2023 15:27:02 +0800 Subject: [PATCH 3/9] delete redundant return --- lyrebird_bugit/template_loader.py | 1 - 1 file changed, 1 deletion(-) diff --git a/lyrebird_bugit/template_loader.py b/lyrebird_bugit/template_loader.py index 958bfc8..cc3ae02 100644 --- a/lyrebird_bugit/template_loader.py +++ b/lyrebird_bugit/template_loader.py @@ -30,7 +30,6 @@ def get_default_template(): template_path = Path(bugit_workspace + bugit_default_template) if bugit_workspace and bugit_default_template and template_path.exists(): return template_path - return def template_list(): From d75f6cb5e84668dc5bde92027fe57413aa5f2ee2 Mon Sep 17 00:00:00 2001 From: ZhaoYangyang0403 Date: Mon, 18 Sep 2023 15:31:05 +0800 Subject: [PATCH 4/9] update version --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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', From a6c11e99d0fc864221b7b88074f1a8c92250cce1 Mon Sep 17 00:00:00 2001 From: ZhaoYangyang0403 Date: Wed, 20 Sep 2023 11:30:50 +0800 Subject: [PATCH 5/9] call autoissue class from template --- lyrebird_bugit/event_handler.py | 9 +++++++++ lyrebird_bugit/manifest.py | 3 ++- lyrebird_bugit/template_loader.py | 26 +++++++++++++++++++++++--- 3 files changed, 34 insertions(+), 4 deletions(-) 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) From 2958824a8563f94dccf7c5794e3e34b4e4a2e79d Mon Sep 17 00:00:00 2001 From: ZhaoYangyang0403 Date: Wed, 20 Sep 2023 12:03:12 +0800 Subject: [PATCH 6/9] add plugin.bugit in config --- lyrebird_bugit/event_handler.py | 2 +- lyrebird_bugit/template_loader.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lyrebird_bugit/event_handler.py b/lyrebird_bugit/event_handler.py index 4458350..217d370 100644 --- a/lyrebird_bugit/event_handler.py +++ b/lyrebird_bugit/event_handler.py @@ -62,7 +62,7 @@ def on_upload_files(msg): def on_notice(msg): - conf_autoissue = application.config.get('autoissue', False) + conf_autoissue = application.config.get('plugin.bugit.autoissue', False) if not conf_autoissue: return template_loader.notice_handler(msg) diff --git a/lyrebird_bugit/template_loader.py b/lyrebird_bugit/template_loader.py index 8dd3bd2..9661752 100644 --- a/lyrebird_bugit/template_loader.py +++ b/lyrebird_bugit/template_loader.py @@ -79,7 +79,7 @@ def notice_handler(msg): return # Filter out messages from unconfigured extensions - checker_switch = application.config.get('autoissue.checker.switch', {}) + checker_switch = application.config.get('plugin.bugit.autoissue.checker_switch', {}) sender_file = msg.get('sender', {}).get('file', '') if sender_file not in checker_switch: return From b5e16121145642aec59e8648463f6b0bd754a774 Mon Sep 17 00:00:00 2001 From: ZhaoYangyang0403 Date: Mon, 25 Sep 2023 19:21:26 +0800 Subject: [PATCH 7/9] add default template check --- lyrebird_bugit/event_handler.py | 8 ++--- lyrebird_bugit/template_loader.py | 49 +++++++++++++++++++++++-------- 2 files changed, 40 insertions(+), 17 deletions(-) diff --git a/lyrebird_bugit/event_handler.py b/lyrebird_bugit/event_handler.py index 217d370..80f0092 100644 --- a/lyrebird_bugit/event_handler.py +++ b/lyrebird_bugit/event_handler.py @@ -62,7 +62,7 @@ def on_upload_files(msg): def on_notice(msg): - conf_autoissue = application.config.get('plugin.bugit.autoissue', False) - if not conf_autoissue: - return - template_loader.notice_handler(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/template_loader.py b/lyrebird_bugit/template_loader.py index 9661752..af79a40 100644 --- a/lyrebird_bugit/template_loader.py +++ b/lyrebird_bugit/template_loader.py @@ -8,6 +8,7 @@ logger = get_logger() +default_template_ready = None def get_workspace(): bugit_workspace = application.config.get('bugit.workspace') @@ -27,14 +28,19 @@ def get_workspace(): def get_default_template_path(): bugit_workspace = application.config.get('bugit.workspace', '') bugit_default_template = application.config.get('bugit.default_template', '') + if default_template_ready is None: + default_template_check(bugit_workspace, bugit_default_template) template_path = Path(bugit_workspace + bugit_default_template) - if bugit_workspace and bugit_default_template and template_path.exists(): + if bugit_default_template: return template_path def template_list(): template_list = [] default_template_path = get_default_template_path() + if not default_template_ready: + return template_list + for template_file in get_workspace().iterdir(): if not template_file.name.endswith('.py'): continue @@ -68,26 +74,43 @@ def template_check(template): template.submit), "BugIt template should have submit function" +def default_template_check(workspace, default_template): + global default_template_ready + + template_path = Path(workspace + default_template) + if not template_path.exists(): + logger.error('Default template path is not existed.') + default_template_ready = False + return + + if application.config.get('event.notice.autoissue.checker'): + if not default_template: + logger.error('Default template is not configured.') + default_template_ready = False + return + template = get_template(template_path) + if not (hasattr(template, 'auto_issue_handler') and callable(template.auto_issue_handler)): + logger.error('BugIt template should have auto_issue_handler function.') + default_template_ready = False + return + + default_template_ready = True + + 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('plugin.bugit.autoissue.checker_switch', {}) - sender_file = msg.get('sender', {}).get('file', '') - if sender_file not in checker_switch: + default_template_path = get_default_template_path() + + if not default_template_ready: 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}') + # Filter out messages with invalid types + if not isinstance(msg, dict): return template = get_template(default_template_path) - template.AutoIssue().auto_issue_handler(msg) + template.auto_issue_handler(msg) From 4600ec71c6944892e241ad1f50f6741f3cc825fa Mon Sep 17 00:00:00 2001 From: ZhaoYangyang0403 Date: Tue, 26 Sep 2023 19:59:55 +0800 Subject: [PATCH 8/9] add last template cache --- lyrebird_bugit/apis.py | 6 ++-- lyrebird_bugit/template_loader.py | 50 ++++++++++++++----------------- 2 files changed, 25 insertions(+), 31 deletions(-) diff --git a/lyrebird_bugit/apis.py b/lyrebird_bugit/apis.py index 0d415bd..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,9 +33,8 @@ def template(): cache.update_all_draft_file(templates) last_selected_template = cache.get_selected_template() - if len(templates) == 1 and last_selected_template != templates[0]['path']: - last_selected_template = templates[0]['path'] - cache.selected_template(last_selected_template, None) + if not last_selected_template and default_template: + last_selected_template = str(default_template) selected_template_index = None for index, template in enumerate(templates): diff --git a/lyrebird_bugit/template_loader.py b/lyrebird_bugit/template_loader.py index af79a40..78c922f 100644 --- a/lyrebird_bugit/template_loader.py +++ b/lyrebird_bugit/template_loader.py @@ -8,7 +8,8 @@ logger = get_logger() -default_template_ready = None +autoissue_ready = None +last_template = None def get_workspace(): bugit_workspace = application.config.get('bugit.workspace') @@ -28,8 +29,6 @@ def get_workspace(): def get_default_template_path(): bugit_workspace = application.config.get('bugit.workspace', '') bugit_default_template = application.config.get('bugit.default_template', '') - if default_template_ready is None: - default_template_check(bugit_workspace, bugit_default_template) template_path = Path(bugit_workspace + bugit_default_template) if bugit_default_template: return template_path @@ -37,15 +36,9 @@ def get_default_template_path(): def template_list(): template_list = [] - default_template_path = get_default_template_path() - if not default_template_ready: - return template_list - for template_file in get_workspace().iterdir(): if not template_file.name.endswith('.py'): continue - if default_template_path and template_file != default_template_path: - continue try: logger.debug(f'Load template {template_file}') template = imp.load_source(template_file.stem, str(template_file)) @@ -74,38 +67,39 @@ def template_check(template): template.submit), "BugIt template should have submit function" -def default_template_check(workspace, default_template): - global default_template_ready +def default_template_check(template_path): + global autoissue_ready - template_path = Path(workspace + default_template) if not template_path.exists(): logger.error('Default template path is not existed.') - default_template_ready = False + autoissue_ready = False return - if application.config.get('event.notice.autoissue.checker'): - if not default_template: - logger.error('Default template is not configured.') - default_template_ready = False - return - template = get_template(template_path) - if not (hasattr(template, 'auto_issue_handler') and callable(template.auto_issue_handler)): - logger.error('BugIt template should have auto_issue_handler function.') - default_template_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 - default_template_ready = True + 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 not default_template_ready: + if autoissue_ready is None: + default_template_check(default_template_path) + + if autoissue_ready == False: return # Filter out messages with invalid types @@ -113,4 +107,4 @@ def notice_handler(msg): return template = get_template(default_template_path) - template.auto_issue_handler(msg) + template.auto_issue(msg) From 618e153d7d72ccb49055c686afd4c04ff320f486 Mon Sep 17 00:00:00 2001 From: ZhaoYangyang0403 Date: Wed, 27 Sep 2023 12:06:31 +0800 Subject: [PATCH 9/9] fix default template check --- README.md | 4 ++++ lyrebird_bugit/template_loader.py | 19 ++++++++++++++----- 2 files changed, 18 insertions(+), 5 deletions(-) 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/template_loader.py b/lyrebird_bugit/template_loader.py index 78c922f..f26b403 100644 --- a/lyrebird_bugit/template_loader.py +++ b/lyrebird_bugit/template_loader.py @@ -27,11 +27,15 @@ def get_workspace(): 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) - if bugit_default_template: - return 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(): @@ -70,6 +74,11 @@ def template_check(template): 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