py
Some checks failed
API接口参数变更检测 / api-param-check (push) Has been cancelled

This commit is contained in:
2026-06-04 17:14:24 +08:00
parent e72c9e81de
commit 2fdd7ec2cc
2 changed files with 21 additions and 11 deletions

View File

@@ -25,26 +25,28 @@ def truncate_text(text: str, max_length: int = MAX_MD_LENGTH) -> str:
def _format_endpoint_block(report: EndpointChangeReport) -> str:
"""
格式化单个接口块,按模板匹配格式输出。
全路径类名显示为 source_file相对仓库根的完整 .java 路径)。
"""
change_type = "新增接口" if report.is_new_endpoint else ("删除接口" if report.is_removed_endpoint else "修改参数")
uri_line = f"**{report.http_method}** `{report.uri}`"
class_line = f"- **全路径类名:** {report.controller_class}"
file_path = report.source_file or report.controller_class
class_line = f"- **全路径类名:** <font color=\"info\">**{file_path}**</font>"
header = [
f"- **变更类型:** {change_type}",
f"- **变更类型:** <font color=\"warning\">**{change_type}**</font>",
f"- **URI** {uri_line}",
class_line,
]
if report.is_removed_endpoint:
return "\n".join(header + [f"<font color=\"warning\">该接口已被移除</font>"])
return "\n".join(header + ["", f"<font color=\"warning\">**该接口已被移除**</font>"])
detail_lines = ["", "---", "", "## 接口参数变动详情", "", "---", ""]
if report.is_new_endpoint:
detail_lines.append("### <font color=\"info\">新增接口参数</font>")
detail_lines.append("### <font color=\"info\">**新增接口参数**</font>")
else:
detail_lines.append("### <font color=\"warning\">参数变更明细</font>")
detail_lines.append("### <font color=\"warning\">**参数变更明细**</font>")
if report.parameter_changes:
for change in report.parameter_changes:
@@ -92,7 +94,7 @@ def build_markdown_notification(
change_type="修改路径",
push_user=push_user,
push_time=push_time,
file_name=report.controller_class,
file_name=report.source_file or report.controller_class,
)
parts.append(path_md)
parts.append("")
@@ -245,13 +247,16 @@ def build_path_change_markdown(
push_time: str,
file_name: str,
) -> str:
"""构建 API路径变更通知匹配 model1.md 模板。"""
"""构建 API路径变更通知匹配 model1.md 模板,并加强高亮"""
old_display = f"<font color=\"warning\">~~`{old_uri}`~~</font>" if old_uri else "-"
new_display = f"<font color=\"info\">**`{new_uri}`**</font>" if new_uri else "<font color=\"comment\">已删除</font>"
parts = [
"# API路径变更通知",
f"- **变更类型:** {change_type}",
f"- **变更类型:** <font color=\"warning\">**{change_type}**</font>",
f"- **修改人:** {push_user}",
f"- **修改时间:** {push_time}",
f"- **全路径类名:** {file_name}",
f"- **全路径类名:** <font color=\"info\">**{file_name}**</font>",
"",
"---",
"",
@@ -261,8 +266,8 @@ def build_path_change_markdown(
"",
"| 项目 | 路径 |",
"|------|------|",
f"| 原路径 | `{old_uri if old_uri else '-'}` |",
f"| 新路径 | `{new_uri if new_uri else '已删除'}` |",
f"| 原路径 | {old_display} |",
f"| 新路径 | {new_display} |",
"",
"---",
]