From d2a147222ea878715aa376e216d4cf97c9032a5f Mon Sep 17 00:00:00 2001 From: Ryo <36154873+RyoJerryYu@users.noreply.github.com> Date: Fri, 14 Jun 2024 02:08:26 +0800 Subject: [PATCH 1/3] feat: more useful info after all plugins skipped --- memos_webhook/plugins/base_plugin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/memos_webhook/plugins/base_plugin.py b/memos_webhook/plugins/base_plugin.py index 4bd22d9..2267018 100644 --- a/memos_webhook/plugins/base_plugin.py +++ b/memos_webhook/plugins/base_plugin.py @@ -174,4 +174,4 @@ async def execute(self, payload: v1.WebhookRequestPayload) -> None: await self.update_memo_content(plugin, payload) return # only execute one plugin - self.logger.info("All plugins executed") + self.logger.info(f"All plugins skipped for {payload.memo.name}") From 6eded577be33a1bf3591290b9649b8534657a317 Mon Sep 17 00:00:00 2001 From: Ryo <36154873+RyoJerryYu@users.noreply.github.com> Date: Fri, 14 Jun 2024 02:18:35 +0800 Subject: [PATCH 2/3] feat: skip update if deleted a memo --- memos_webhook/plugins/base_plugin.py | 9 +++++++-- memos_webhook/plugins/you_get_plugin.py | 4 +++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/memos_webhook/plugins/base_plugin.py b/memos_webhook/plugins/base_plugin.py index 2267018..05458a3 100644 --- a/memos_webhook/plugins/base_plugin.py +++ b/memos_webhook/plugins/base_plugin.py @@ -143,10 +143,15 @@ async def update_memo_content( Once the task triggered, will replace the `#tag` with `#tag/done`. If the `#tag` not exists, will add the `#tag/done` to first line. """ - self.logger.debug(f"Background task started with param: {payload.to_json()}") + self.logger.debug(f"Plugin task started with param: {payload.to_json()}") res_memo = await plugin.task(payload, self.memos_cli) - self.logger.info("Background task success completed") + self.logger.info("Plugin task success completed") + assert res_memo is not None, "task should return a memo" + + if payload.activity_type == "memos.memo.deleted": + self.logger.info("Memo deleted, skip update memo content") + return # update memo if plugin.positive_tag() in res_memo.content: diff --git a/memos_webhook/plugins/you_get_plugin.py b/memos_webhook/plugins/you_get_plugin.py index 9f6bf1b..91cbe22 100644 --- a/memos_webhook/plugins/you_get_plugin.py +++ b/memos_webhook/plugins/you_get_plugin.py @@ -67,7 +67,9 @@ async def task( # extract urls urls = extract_urls(payload.memo.content, self.patterns) if not urls: - self.logger.info("No urls found") + self.logger.info("Triggered but no urls found") + # trigger but no urls found, it may have a positive tag. + # Should update the tag and make sure it will not be triggered again return payload.memo self.logger.info(f"Extracted urls: {urls}") From 7fedabd80e62546051b1c07be6d22b5108c8fd2a Mon Sep 17 00:00:00 2001 From: Ryo <36154873+RyoJerryYu@users.noreply.github.com> Date: Fri, 14 Jun 2024 02:19:48 +0800 Subject: [PATCH 3/3] feat: activity type to constants --- memos_webhook/constants/__init__.py | 3 +++ memos_webhook/plugins/base_plugin.py | 3 ++- memos_webhook/plugins/you_get_plugin.py | 4 +++- 3 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 memos_webhook/constants/__init__.py diff --git a/memos_webhook/constants/__init__.py b/memos_webhook/constants/__init__.py new file mode 100644 index 0000000..df27288 --- /dev/null +++ b/memos_webhook/constants/__init__.py @@ -0,0 +1,3 @@ +ACTIVITY_TYPE_CREATED = "memos.memo.created" +ACTIVITY_TYPE_UPDATED = "memos.memo.updated" +ACTIVITY_TYPE_DELETED = "memos.memo.deleted" \ No newline at end of file diff --git a/memos_webhook/plugins/base_plugin.py b/memos_webhook/plugins/base_plugin.py index 05458a3..4b0bbfb 100644 --- a/memos_webhook/plugins/base_plugin.py +++ b/memos_webhook/plugins/base_plugin.py @@ -4,6 +4,7 @@ import betterproto.lib.google.protobuf as pb +from memos_webhook.constants import ACTIVITY_TYPE_DELETED from memos_webhook.dependencies.memos_cli import MemosCli from memos_webhook.proto_gen.memos.api import v1 from memos_webhook.utils.logger import logger @@ -149,7 +150,7 @@ async def update_memo_content( self.logger.info("Plugin task success completed") assert res_memo is not None, "task should return a memo" - if payload.activity_type == "memos.memo.deleted": + if payload.activity_type == ACTIVITY_TYPE_DELETED: self.logger.info("Memo deleted, skip update memo content") return diff --git a/memos_webhook/plugins/you_get_plugin.py b/memos_webhook/plugins/you_get_plugin.py index 91cbe22..b0f0524 100644 --- a/memos_webhook/plugins/you_get_plugin.py +++ b/memos_webhook/plugins/you_get_plugin.py @@ -8,6 +8,8 @@ import aiofiles.os import betterproto.lib.google.protobuf as pb +from memos_webhook.constants import (ACTIVITY_TYPE_CREATED, + ACTIVITY_TYPE_UPDATED) from memos_webhook.dependencies.config import YouGetPluginConfig from memos_webhook.dependencies.memos_cli import MemosCli from memos_webhook.proto_gen.memos.api import v1 @@ -35,7 +37,7 @@ def __init__(self, cfg: YouGetPluginConfig) -> None: self.patterns = [re.compile(pattern) for pattern in cfg.patterns] def activity_types(self) -> list[str]: - return ["memos.memo.created", "memos.memo.updated"] + return [ACTIVITY_TYPE_CREATED, ACTIVITY_TYPE_UPDATED] @override def tag(self) -> str: