Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v1.15.0 - default template according to business #56

Merged
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)
]
)
52 changes: 50 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,14 @@
return metadata_dir


def get_default_template_path():
Fixed Show fixed Hide fixed

Check notice

Code scanning / CodeQL

Explicit returns mixed with implicit (fall through) returns Note

Mixing implicit and explicit returns may indicate an error as implicit returns always return None.
bugit_workspace = application.config.get('bugit.workspace', '')
bugit_default_template = application.config.get('bugit.default_template', '')
Copy link
Member

@yumiguan yumiguan Sep 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bugit_default_template = application.config.get('bugit.default_template')
if not bugit_default_template:
    return

bugit_workspace = application.config.get('bugit.workspace')
if not bugit_workspace:
    return

return Path(bugit_workspace) / Path(bugit_default_template)

template_path = Path(bugit_workspace + bugit_default_template)
if bugit_default_template:
return template_path


def template_list():
template_list = []
for template_file in get_workspace().iterdir():
Expand Down Expand Up @@ -57,6 +67,44 @@
template.submit), "BugIt template should have submit function"


def default_template_check(template_path):
global autoissue_ready

if not template_path.exists():
Copy link
Member

@yumiguan yumiguan Sep 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if not template_path:
 ...
    return

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
Loading