Skip to content

Commit

Permalink
Merge pull request #56 from ZhaoYangyang0403/feature/default-template…
Browse files Browse the repository at this point in the history
…-according-to-business

default template according to business
  • Loading branch information
yumiguan authored Sep 27, 2023
2 parents 1793c6c + 618e153 commit 48b290e
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 4 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ BugIt支持自动填充Lyrebird运行过程中抓取到的数据信息。

![BugIt获取报警信息](./image/bugit_alert.gif)

此外,还支持针对指定检查器的报警进行自动开Bug。

通过配置可以指定检查器,BugIt会将这些检查器的报警信息送入配置指定的脚本内,在脚本内自定义对报警信息的处理,即可实现Bug的自动上报功能。

## 缓存功能

按下[Commond]+[s]键,会将Bug相关字段信息进行存储。
Expand Down
4 changes: 4 additions & 0 deletions lyrebird_bugit/apis.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down
9 changes: 9 additions & 0 deletions lyrebird_bugit/event_handler.py
Original file line number Diff line number Diff line change
@@ -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()
Expand Down Expand Up @@ -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)
3 changes: 2 additions & 1 deletion lyrebird_bugit/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
]
)
61 changes: 59 additions & 2 deletions lyrebird_bugit/template_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

logger = get_logger()

autoissue_ready = None
last_template = None

def get_workspace():
bugit_workspace = application.config.get('bugit.workspace')
Expand All @@ -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():
Expand Down Expand Up @@ -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)
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 48b290e

Please sign in to comment.