From 1c1a78c65c1ca6a8f905b2c34e7b58118e6bfaea Mon Sep 17 00:00:00 2001 From: ZhaoYangyang0403 Date: Tue, 19 Sep 2023 20:06:01 +0800 Subject: [PATCH 1/5] support auto issue --- lyrebird/manager.py | 12 ++++++++++++ lyrebird/notice_center.py | 16 +++++++++++++--- lyrebird/version.py | 2 +- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/lyrebird/manager.py b/lyrebird/manager.py index 4b4924cae..e0b23a99d 100644 --- a/lyrebird/manager.py +++ b/lyrebird/manager.py @@ -7,6 +7,7 @@ import socket import threading import traceback +import imp from pathlib import Path from packaging.version import parse as vparse @@ -197,6 +198,17 @@ def run(args: argparse.Namespace): # Mock mush init after other servers application.server['mock'] = LyrebirdMockServer() + conf_autoissue = application.config.get('autoissue', False) + if conf_autoissue: + 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_workspace and bugit_default_template and template_path.exists(): + template = imp.load_source(Path(template_path).stem, str(template_path)) + application.server['issue'] = template.AutoIssueServer() + else: + logger.error(f'Init Auto Issue Server Failed. Template path is configured incorrectly: {template_path}') + # handle progress message application.process_status_listener() diff --git a/lyrebird/notice_center.py b/lyrebird/notice_center.py index e8e9f713e..fe755feb8 100644 --- a/lyrebird/notice_center.py +++ b/lyrebird/notice_center.py @@ -6,12 +6,14 @@ from lyrebird import log from lyrebird import application from lyrebird.mock import context +from copy import deepcopy logger = log.get_logger() class NoticeCenter(): def __init__(self): + self.checker_switch = application.config.get('autoissue.checker.switch', {}) self.HISTORY_NOTICE = None self.notice_hashmap = {} self.notice_list = [] @@ -69,14 +71,22 @@ def load_history_notice(self): logger.error('Load history notice fail!') traceback.print_exc() - def new_notice(self, msg): + def new_notice(self, msg_origin): """ display new notice - msg: message dict + msg_origin: message dict """ + msg = deepcopy(msg_origin) + alert = True + # if notice need to be issued automatically, no alert + sender_file = msg.get('sender', {}).get('file', '') + if sender_file in self.checker_switch: + msg['title'] = f"[AutoIssue] {msg.get('title')}" + alert = False + unique_key = msg.get('title') if self.notice_hashmap.get(unique_key): self.notice_hashmap[unique_key]['noticeList'].append(msg) @@ -86,7 +96,7 @@ def new_notice(self, msg): self.notice_hashmap.update( { unique_key: { - 'alert': True, + 'alert': alert, 'noticeList': [msg] } } diff --git a/lyrebird/version.py b/lyrebird/version.py index b1c9286e4..c8a54f5af 100644 --- a/lyrebird/version.py +++ b/lyrebird/version.py @@ -1,3 +1,3 @@ -IVERSION = (2, 19, 1) +IVERSION = (2, 20, 0) VERSION = ".".join(str(i) for i in IVERSION) LYREBIRD = "Lyrebird " + VERSION From 6f1f3c8ba0843333ee92ae69473a648ec549e636 Mon Sep 17 00:00:00 2001 From: ZhaoYangyang0403 Date: Wed, 20 Sep 2023 09:51:16 +0800 Subject: [PATCH 2/5] move init autoissue --- lyrebird/manager.py | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/lyrebird/manager.py b/lyrebird/manager.py index e0b23a99d..4b4924cae 100644 --- a/lyrebird/manager.py +++ b/lyrebird/manager.py @@ -7,7 +7,6 @@ import socket import threading import traceback -import imp from pathlib import Path from packaging.version import parse as vparse @@ -198,17 +197,6 @@ def run(args: argparse.Namespace): # Mock mush init after other servers application.server['mock'] = LyrebirdMockServer() - conf_autoissue = application.config.get('autoissue', False) - if conf_autoissue: - 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_workspace and bugit_default_template and template_path.exists(): - template = imp.load_source(Path(template_path).stem, str(template_path)) - application.server['issue'] = template.AutoIssueServer() - else: - logger.error(f'Init Auto Issue Server Failed. Template path is configured incorrectly: {template_path}') - # handle progress message application.process_status_listener() From 888f2cc41d56304a713e6fb5b98cb61836e3b34b Mon Sep 17 00:00:00 2001 From: ZhaoYangyang0403 Date: Wed, 20 Sep 2023 11:59:15 +0800 Subject: [PATCH 3/5] add plugin.bugit in config --- lyrebird/notice_center.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lyrebird/notice_center.py b/lyrebird/notice_center.py index fe755feb8..aea00cead 100644 --- a/lyrebird/notice_center.py +++ b/lyrebird/notice_center.py @@ -13,7 +13,7 @@ class NoticeCenter(): def __init__(self): - self.checker_switch = application.config.get('autoissue.checker.switch', {}) + self.checker_switch = application.config.get('plugin.bugit.autoissue.checker_switch', {}) self.HISTORY_NOTICE = None self.notice_hashmap = {} self.notice_list = [] From 695148357e6adf91e01021220e2b430ffb478a44 Mon Sep 17 00:00:00 2001 From: ZhaoYangyang0403 Date: Thu, 21 Sep 2023 19:26:20 +0800 Subject: [PATCH 4/5] move config check into CheckerEventHandler --- lyrebird/checker/event.py | 12 ++++++++++++ lyrebird/notice_center.py | 15 +++------------ 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/lyrebird/checker/event.py b/lyrebird/checker/event.py index 4f9af54b3..9480ece37 100644 --- a/lyrebird/checker/event.py +++ b/lyrebird/checker/event.py @@ -1,3 +1,4 @@ +import inspect from lyrebird import application from .. import checker @@ -21,10 +22,21 @@ def issue(self, title, message): "title": title, "message": message } + self.check_notice(notice) application.server['event'].publish('notice', notice) def publish(self, channel, message, *args, **kwargs): + if channel == 'notice': + self.check_notice(message) application.server['event'].publish(channel, message, *args, **kwargs) + + def check_notice(self, notice): + stack = inspect.stack() + script_path = stack[2].filename + script_name = script_path[script_path.rfind('/') + 1:] + if script_name in application.config.get('plugin.bugit.autoissue.checker_switch', {}): + notice['title'] = f"【Extension】{notice.get('title')}" + notice['alert'] = False @staticmethod def register(func_info): diff --git a/lyrebird/notice_center.py b/lyrebird/notice_center.py index aea00cead..7971fe086 100644 --- a/lyrebird/notice_center.py +++ b/lyrebird/notice_center.py @@ -6,14 +6,12 @@ from lyrebird import log from lyrebird import application from lyrebird.mock import context -from copy import deepcopy logger = log.get_logger() class NoticeCenter(): def __init__(self): - self.checker_switch = application.config.get('plugin.bugit.autoissue.checker_switch', {}) self.HISTORY_NOTICE = None self.notice_hashmap = {} self.notice_list = [] @@ -71,23 +69,16 @@ def load_history_notice(self): logger.error('Load history notice fail!') traceback.print_exc() - def new_notice(self, msg_origin): + def new_notice(self, msg): """ display new notice - msg_origin: message dict + msg: message dict """ - msg = deepcopy(msg_origin) - alert = True - # if notice need to be issued automatically, no alert - sender_file = msg.get('sender', {}).get('file', '') - if sender_file in self.checker_switch: - msg['title'] = f"[AutoIssue] {msg.get('title')}" - alert = False - unique_key = msg.get('title') + alert = msg.get('alert', True) if self.notice_hashmap.get(unique_key): self.notice_hashmap[unique_key]['noticeList'].append(msg) if self.notice_hashmap[unique_key].get('alert'): From e6fac34d43890ff37017d85cb732e660dcaa7603 Mon Sep 17 00:00:00 2001 From: ZhaoYangyang0403 Date: Fri, 22 Sep 2023 17:28:38 +0800 Subject: [PATCH 5/5] change config name to event.notice --- lyrebird/checker/event.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lyrebird/checker/event.py b/lyrebird/checker/event.py index 9480ece37..39ddcdb11 100644 --- a/lyrebird/checker/event.py +++ b/lyrebird/checker/event.py @@ -34,7 +34,7 @@ def check_notice(self, notice): stack = inspect.stack() script_path = stack[2].filename script_name = script_path[script_path.rfind('/') + 1:] - if script_name in application.config.get('plugin.bugit.autoissue.checker_switch', {}): + if script_name in application.config.get('event.notice.autoissue.checker', []): notice['title'] = f"【Extension】{notice.get('title')}" notice['alert'] = False