字段说明测试
This commit is contained in:
@@ -22,6 +22,46 @@ def truncate_text(text: str, max_length: int = MAX_MD_LENGTH) -> str:
|
||||
return text[:max_length] + "\n\n<font color=\"comment\">... 消息过长,已截断</font>"
|
||||
|
||||
|
||||
def _format_param_table(changes: List) -> List[str]:
|
||||
"""按 model.md 生成参数变更 Markdown 表格。"""
|
||||
if not changes:
|
||||
return ['<font color="comment">无</font>']
|
||||
lines = [
|
||||
"",
|
||||
"| 字段 | 说明 | 变更 |",
|
||||
"|------|------|------|",
|
||||
]
|
||||
for change in changes:
|
||||
lines.append(change.to_table_row())
|
||||
return lines
|
||||
|
||||
|
||||
def _format_param_details_section(report: EndpointChangeReport) -> List[str]:
|
||||
"""生成接口参数变动详情区块(对齐 model.md)。"""
|
||||
body_changes = [c for c in report.parameter_changes if c.source == "body"]
|
||||
regular_changes = [c for c in report.parameter_changes if c.source != "body"]
|
||||
lines = ["", "---", "", "## 接口参数变动详情", "", "---", ""]
|
||||
|
||||
if body_changes:
|
||||
lines.append("### 类对象变更")
|
||||
lines.append("")
|
||||
lines.append("- **参数变更列表:**")
|
||||
lines.extend(_format_param_table(body_changes))
|
||||
lines.append("")
|
||||
|
||||
if regular_changes:
|
||||
lines.append("### 普通参数变更(非对象字段)")
|
||||
lines.append("")
|
||||
lines.append("- **参数变更列表:**")
|
||||
lines.extend(_format_param_table(regular_changes))
|
||||
lines.append("")
|
||||
|
||||
if not body_changes and not regular_changes:
|
||||
lines.append('<font color="comment">无</font>')
|
||||
|
||||
return lines
|
||||
|
||||
|
||||
def _format_endpoint_block(report: EndpointChangeReport) -> str:
|
||||
"""
|
||||
格式化单个接口块,按模板匹配格式输出。
|
||||
@@ -41,21 +81,7 @@ def _format_endpoint_block(report: EndpointChangeReport) -> str:
|
||||
if report.is_removed_endpoint:
|
||||
return "\n".join(header + ["", f"<font color=\"warning\">**该接口已被移除**</font>"])
|
||||
|
||||
detail_lines = ["", "---------------------------------------", "", "## 【接口参数变动详情】", ""]
|
||||
|
||||
if report.is_new_endpoint:
|
||||
detail_lines.append("### <font color=\"info\">**新增接口参数**</font>")
|
||||
else:
|
||||
detail_lines.append("### <font color=\"warning\">**参数变更明细**</font>")
|
||||
|
||||
if report.parameter_changes:
|
||||
for change in report.parameter_changes:
|
||||
md = change.to_markdown_line(plain=report.is_new_endpoint)
|
||||
detail_lines.append(md)
|
||||
else:
|
||||
detail_lines.append('<font color="comment">无</font>')
|
||||
|
||||
return "\n".join(header + detail_lines)
|
||||
return "\n".join(header + _format_param_details_section(report))
|
||||
|
||||
|
||||
def build_markdown_notification(
|
||||
@@ -142,7 +168,7 @@ def build_markdown_notification(
|
||||
parts.append(path_md)
|
||||
parts.append("")
|
||||
|
||||
# 4. 普通参数变更(非路径变更)仍使用原有格式
|
||||
# 4. 普通参数变更(非路径变更)仍使用 model.md 格式
|
||||
if changed_reports:
|
||||
parts.append("# 【API参数变更通知】")
|
||||
parts.append(f"- **修改人:** {push_user}")
|
||||
@@ -291,6 +317,9 @@ def send_parameter_change_notification(
|
||||
push_time=push_time,
|
||||
file_name=report.source_file or report.controller_class,
|
||||
)
|
||||
if report.parameter_changes:
|
||||
param_section = "\n".join(_format_param_details_section(report)).strip()
|
||||
md = f"{md}\n\n{param_section}"
|
||||
if _post_wecom_markdown(webhook_url, md):
|
||||
sent += 1
|
||||
print(f"第 {sent} 条通知已发送到企业微信(新增接口)")
|
||||
@@ -325,9 +354,9 @@ def send_parameter_change_notification(
|
||||
|
||||
# ========== 3. 参数变更通知(独立分支) ==========
|
||||
if changed_reports:
|
||||
# 构建参数变更通知(只包含参数变更报告)
|
||||
# 构建参数变更通知(只包含参数变更报告,对齐 model.md)
|
||||
parts: List[str] = []
|
||||
parts.append("# API参数变更通知")
|
||||
parts.append("# 【API参数变更通知】")
|
||||
parts.append(f"- **修改人:** {push_user if push_user.startswith('@') else '@' + push_user}")
|
||||
parts.append(f"- **修改时间:** {push_time}")
|
||||
parts.append("")
|
||||
|
||||
Reference in New Issue
Block a user