Skip to content

Commit

Permalink
feat: 提供 author_id 的储存
Browse files Browse the repository at this point in the history
  • Loading branch information
BigOrangeQWQ committed Sep 4, 2024
1 parent c6852c0 commit c106115
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 12 deletions.
15 changes: 9 additions & 6 deletions src/plugins/publish/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,10 @@ def strip_ansi(text: str | None) -> str:

async def validate_plugin_info_from_issue(issue: "Issue") -> ValidationDict:
"""从议题中提取插件信息"""
body: str = issue.body if issue.body else ""
author: str | None = issue.user.login if issue.user else ""
body = issue.body if issue.body else ""
author = issue.user.id if issue.user else ""
author_id = issue.user.id if issue.user else None

if issue.user:
logger.info("Issue用户信息:" + str(issue.user.model_dump()))
raw_data: dict[str, Any] = extract_publish_info_from_issue(
{
"module_name": PLUGIN_MODULE_NAME_PATTERN,
Expand Down Expand Up @@ -84,6 +83,7 @@ async def validate_plugin_info_from_issue(issue: "Issue") -> ValidationDict:
"metadata": plugin_test_metadata,
"previous_data": previous_data,
"author": author,
"author_id": author_id,
}
)
# 如果插件测试被跳过,则从议题中获取信息
Expand Down Expand Up @@ -139,8 +139,8 @@ async def validate_plugin_info_from_issue(issue: "Issue") -> ValidationDict:
async def validate_bot_info_from_issue(issue: "Issue") -> ValidationDict:
body = issue.body if issue.body else ""
author = issue.user.login if issue.user else ""

raw_data: dict[str, str] = extract_publish_info_from_issue(
author_id = issue.user.id if issue.user else None
raw_data: dict[str, Any] = extract_publish_info_from_issue(
{
"name": BOT_NAME_PATTERN,
"desc": BOT_DESC_PATTERN,
Expand All @@ -150,13 +150,15 @@ async def validate_bot_info_from_issue(issue: "Issue") -> ValidationDict:
body,
)
raw_data["author"] = author
raw_data["author_id"] = author_id

return validate_info(PublishType.BOT, raw_data)


async def validate_adapter_info_from_issue(issue: "Issue") -> ValidationDict:
body = issue.body if issue.body else ""
author = issue.user.login if issue.user else ""
author_id = issue.user.id if issue.user else None
raw_data: dict[str, Any] = extract_publish_info_from_issue(
{
"module_name": ADAPTER_MODULE_NAME_PATTERN,
Expand All @@ -171,6 +173,7 @@ async def validate_adapter_info_from_issue(issue: "Issue") -> ValidationDict:
with plugin_config.input_config.adapter_path.open("r", encoding="utf-8") as f:
previous_data: list[dict[str, str]] = json.load(f)
raw_data["author"] = author
raw_data["author_id"] = author_id
raw_data["previous_data"] = previous_data

return validate_info(PublishType.ADAPTER, raw_data)
1 change: 1 addition & 0 deletions src/utils/store_test/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class Plugin(TagModel):
name: str
desc: str
author: str
author_id: int | None = None
homepage: str
tags: list[Tag]
is_official: bool
Expand Down
10 changes: 7 additions & 3 deletions src/utils/store_test/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
ADAPTERS_PATH,
BOTS_PATH,
DRIVERS_PATH,
PLUGIN_CONFIG_PATH,
PLUGIN_KEY_TEMPLATE,
PLUGINS_PATH,
RESULTS_PATH,
Expand Down Expand Up @@ -113,7 +114,11 @@ async def test_plugin(
plugin_data (str | None): 插件数据,不为 None 时,直接使用该数据且跳过测试
"""
plugin = self._store_plugins[key]
config = config or self.read_plugin_config(key)

# 假设传入了 config, 则需要更新 plugin_config 文件
if config:
self._plugin_configs[key] = config
config = self.read_plugin_config(key)

new_result, new_plugin = await validate_plugin(
plugin=plugin,
Expand Down Expand Up @@ -173,7 +178,6 @@ async def merge_data(
"""
results: dict[str, TestResult] = {}
plugins: dict[str, Plugin] = {}

for key in self._store_plugins:
if key in new_results:
results[key] = new_results[key]
Expand Down Expand Up @@ -209,7 +213,7 @@ async def run_single_plugin(
config: str | None = None,
):
"""
运行单次插件测试
运行单次插件测试,来自 trigger_registry_update
Args:
key (str): 插件标识符
Expand Down
4 changes: 1 addition & 3 deletions src/utils/store_test/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
from functools import cache
from pathlib import Path
from typing import Any
from collections.abc import Mapping

import httpx
from pydantic import BaseModel
from pydantic_core import to_jsonable_python


Expand All @@ -18,7 +16,7 @@ def load_json(url: str) -> Any:
return r.json()


def dump_json(path: Path, data: Mapping[str, BaseModel] | list[BaseModel]):
def dump_json(path: Path, data: Any):
"""保存 JSON 文件
为减少文件大小,还需手动设置 separators
Expand Down
1 change: 1 addition & 0 deletions src/utils/validation/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ class PublishInfo(abc.ABC, BaseModel):
name: str = Field(max_length=NAME_MAX_LENGTH)
desc: str
author: str
author_id: int
homepage: str
tags: list[Tag] = Field(max_length=3)
is_official: bool = Field(default=False)
Expand Down

0 comments on commit c106115

Please sign in to comment.