Skip to content

Commit a5e3cb3

Browse files
authored
Merge pull request #7 from RyoJerryYu/feat-update-multi-for-plugins
feat: update multi for plugins
2 parents b7e0020 + 31ff16d commit a5e3cb3

File tree

3 files changed

+15
-13
lines changed

3 files changed

+15
-13
lines changed

memos_webhook/app.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ async def webhook_handler(
7777
"""The new webhook handler, use protojson."""
7878
dict_json = await req.json()
7979
logger.debug(f"webhook handler received request: {dict_json}")
80-
logger.debug(f"type: {type(dict_json)}")
8180

8281
proto_payload = v1.WebhookRequestPayload().from_dict(dict_json)
8382
background_tasks.add_task(webhook_task, proto_payload, executor)

memos_webhook/plugins/base_plugin.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,15 @@
1414

1515
class PluginProtocol(Protocol):
1616
"""The protocol that plugin executor trully need a plugin to implement.
17-
17+
1818
You should implement `BasePlugin` instead of this protocol.
1919
Unless you know what you are doing."""
20+
2021
def positive_tag(self) -> str: ...
2122
def negative_tag(self) -> str: ...
22-
async def task(self, payload: v1.WebhookRequestPayload, memos_cli: MemosCli) -> v1.Memo: ...
23+
async def task(
24+
self, payload: v1.WebhookRequestPayload, memos_cli: MemosCli
25+
) -> v1.Memo: ...
2326
def should_trigger(self, payload: v1.WebhookRequestPayload) -> bool: ...
2427

2528

@@ -60,7 +63,9 @@ def tag(self) -> str:
6063
...
6164

6265
@abstractmethod
63-
async def task(self, payload: v1.WebhookRequestPayload, memos_cli: MemosCli) -> v1.Memo:
66+
async def task(
67+
self, payload: v1.WebhookRequestPayload, memos_cli: MemosCli
68+
) -> v1.Memo:
6469
"""The webhook task function.
6570
6671
Return the modified memo, and the plugin will auto update the memo with modified content and negative tag.
@@ -138,9 +143,7 @@ async def update_memo_content(
138143
Once the task triggered, will replace the `#tag` with `#tag/done`.
139144
If the `#tag` not exists, will add the `#tag/done` to first line.
140145
"""
141-
self.logger.debug(
142-
f"Background task started with param: {payload.to_json()}"
143-
)
146+
self.logger.debug(f"Background task started with param: {payload.to_json()}")
144147

145148
res_memo = await plugin.task(payload, self.memos_cli)
146149
self.logger.info("Background task success completed")
@@ -169,5 +172,6 @@ async def execute(self, payload: v1.WebhookRequestPayload) -> None:
169172
continue
170173

171174
await self.update_memo_content(plugin, payload)
175+
return # only execute one plugin
172176

173177
self.logger.info("All plugins executed")

memos_webhook/plugins/you_get_plugin.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ def additional_trigger(self, payload: v1.WebhookRequestPayload) -> bool:
4949
return False
5050

5151
@override
52-
async def task(self, payload: v1.WebhookRequestPayload, memos_cli: MemosCli) -> v1.Memo:
52+
async def task(
53+
self, payload: v1.WebhookRequestPayload, memos_cli: MemosCli
54+
) -> v1.Memo:
5355
memo_name = payload.memo.name
5456
self.logger.info(f"Start {self.cfg.name} webhook task for memo: {memo_name}")
5557

@@ -66,7 +68,7 @@ async def task(self, payload: v1.WebhookRequestPayload, memos_cli: MemosCli) ->
6668
urls = extract_urls(payload.memo.content, self.patterns)
6769
if not urls:
6870
self.logger.info("No urls found")
69-
return
71+
return payload.memo
7072
self.logger.info(f"Extracted urls: {urls}")
7173

7274
# mkdir
@@ -124,7 +126,4 @@ async def task(self, payload: v1.WebhookRequestPayload, memos_cli: MemosCli) ->
124126
)
125127
self.logger.info(f"Set memo resources: {[res.name for res in all_resources]}")
126128

127-
return v1.Memo(
128-
name=memo_name,
129-
content=payload.memo.content,
130-
)
129+
return payload.memo # you-get plugin do not modify memo content

0 commit comments

Comments
 (0)