Skip to content

Commit

Permalink
feat: 插件测试时检查元数据的配置是否为 BaseModel 子类 (#195)
Browse files Browse the repository at this point in the history
  • Loading branch information
he0119 authored Oct 21, 2023
1 parent 5caaff9 commit 7451b13
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/lang/zh-CN/

## [Unreleased]

### Added

- 插件测试时检查元数据的配置是否为 BaseModel 子类

### Fixed

- 修复未通过标签判断是否是插件发布的问题
Expand Down
9 changes: 9 additions & 0 deletions src/utils/plugin_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import os
from nonebot import init, load_plugin, require
from pydantic import BaseModel
class SetEncoder(json.JSONEncoder):
Expand All @@ -58,6 +59,14 @@ def default(self, obj):
with open(os.environ["GITHUB_OUTPUT"], "a", encoding="utf8") as f:
f.write(f"METADATA<<EOF\\n{{json.dumps(metadata, cls=SetEncoder)}}\\nEOF\\n")
try:
if plugin.metadata.config and not issubclass(plugin.metadata.config, BaseModel):
print("插件配置项不是 Pydantic BaseModel 的子类")
exit(1)
except TypeError:
print("插件配置项应该为 Pydantic BaseModel 子类而不是实例")
exit(1)
{}
"""

Expand Down

0 comments on commit 7451b13

Please sign in to comment.