Skip to content

Commit

Permalink
fix: 修复发布流程检测判定与流程
Browse files Browse the repository at this point in the history
  • Loading branch information
BigOrangeQWQ committed Sep 9, 2024
1 parent 4110fed commit 1cbe2ad
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
7 changes: 3 additions & 4 deletions src/plugins/publish/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ async def check_rule(
event: IssuesOpened | IssuesReopened | IssuesEdited | IssueCommentCreated,
publish_type: PublishType | None = Depends(get_type_by_labels),
) -> bool:
logger.info(f"评论来自: {event.model_dump()}")
if (
isinstance(event, IssueCommentCreated)
and event.payload.comment.user
Expand All @@ -144,10 +143,10 @@ async def check_rule(
return False
if (
isinstance(event, IssuesEdited)
and event.payload.sender.name
and event.payload.sender.name.endswith(BOT_MARKER)
and event.payload.sender.login
and event.payload.sender.login.endswith(BOT_MARKER)
):
logger.info("修改来自机器人,已跳过")
logger.info("议题修改来自机器人,已跳过")
if event.payload.issue.pull_request:
logger.info("评论在拉取请求下,已跳过")
return False
Expand Down
13 changes: 8 additions & 5 deletions src/utils/validation/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,12 @@ class ValidationDict(BaseModel):
data: dict[str, Any]
errors: list[ErrorDetails]

@field_validator("data")
@field_validator("data", mode="before")
@classmethod
def data_validator(cls, v: dict[str, Any] | BaseModel) -> dict[str, Any]:
"""
保证 data 数据是一个字典,而非 Model 实例
"""
if isinstance(v, BaseModel):
return v.model_dump()
elif isinstance(v, dict):
Expand Down Expand Up @@ -138,8 +141,6 @@ def collect_valid_values(
raise PydanticCustomError("validation_context", "未获取到验证上下文")

result = handler(v)
if isinstance(result, BaseModel):
result = result.model_dump()
context["valid_data"][info.field_name] = result
return result

Expand Down Expand Up @@ -173,7 +174,7 @@ class PluginPublishInfo(PublishInfo, PyPIMixin):
"""插件类型"""
supported_adapters: list[str] | None
"""插件支持的适配器"""
load: bool
load: bool = False
""""插件测试结果"""
metadata: Metadata
"""插件测试元数据"""
Expand Down Expand Up @@ -232,6 +233,8 @@ def plugin_test_load_validator(cls, v: bool, info: ValidationInfo) -> bool:
context = info.context
if context is None:
raise PydanticCustomError("validation_context", "未获取到验证上下文")

context["load"] = v # 提供给元数据验证器使用
if v or context.get("skip_plugin_test"):
return True
raise PydanticCustomError(
Expand All @@ -253,7 +256,7 @@ def plugin_test_metadata_validator(
"plugin.metadata",
"插件缺少元数据",
{
"plugin_test_result": context.get("load"),
"plugin_test_result": context.get("load", True),
},
)
return v
Expand Down

0 comments on commit 1cbe2ad

Please sign in to comment.