Skip to content

Commit

Permalink
call autoissue class from template
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhaoYangyang0403 committed Sep 20, 2023
1 parent d75f6cb commit a6c11e9
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
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):
conf_autoissue = application.config.get('autoissue', False)
if not conf_autoissue:
return
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)
]
)
26 changes: 23 additions & 3 deletions lyrebird_bugit/template_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def get_workspace():
return metadata_dir


def get_default_template():
def get_default_template_path():

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', '')
template_path = Path(bugit_workspace + bugit_default_template)
Expand All @@ -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}')
Expand Down Expand Up @@ -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)

0 comments on commit a6c11e9

Please sign in to comment.