This commit is contained in:
@@ -24,40 +24,37 @@ def truncate_text(text: str, max_length: int = MAX_MD_LENGTH) -> str:
|
||||
|
||||
def _format_endpoint_block(report: EndpointChangeReport) -> str:
|
||||
"""
|
||||
格式化单个接口块。
|
||||
|
||||
新增接口:只列参数,不出现「参数变更」字样。
|
||||
变更接口:用颜色区分增删改。
|
||||
删除接口:整接口标红。
|
||||
格式化单个接口块,按模板匹配格式输出。
|
||||
"""
|
||||
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}"
|
||||
|
||||
header = [
|
||||
f"- **变更类型:** {change_type}",
|
||||
f"- **URI:** {uri_line}",
|
||||
class_line,
|
||||
]
|
||||
|
||||
if report.is_removed_endpoint:
|
||||
return (
|
||||
f"### <font color=\"warning\">【已删除接口】</font>\n"
|
||||
f"{uri_line}\n"
|
||||
f"<font color=\"comment\">该接口已被移除</font>"
|
||||
)
|
||||
return "\n".join(header + [f"<font color=\"warning\">该接口已被移除</font>"])
|
||||
|
||||
detail_lines = ["", "---", "", "## 接口参数变动详情", "", "---", ""]
|
||||
|
||||
if report.is_new_endpoint:
|
||||
lines = [
|
||||
f"### <font color=\"info\">【新增接口】</font> {uri_line}",
|
||||
]
|
||||
if report.parameter_changes:
|
||||
for change in report.parameter_changes:
|
||||
lines.append(change.to_markdown_line(plain=True))
|
||||
else:
|
||||
lines.append('<font color="comment">无入参</font>')
|
||||
return "\n".join(lines)
|
||||
|
||||
# 已有接口的参数变更
|
||||
lines = [f"### {uri_line}"]
|
||||
if report.parameter_changes:
|
||||
for change in report.parameter_changes:
|
||||
lines.append(change.to_markdown_line(plain=False))
|
||||
detail_lines.append("### <font color=\"info\">新增接口参数</font>")
|
||||
else:
|
||||
lines.append('<font color="comment">(无参数变化)</font>')
|
||||
return "\n".join(lines)
|
||||
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)
|
||||
|
||||
|
||||
def build_markdown_notification(
|
||||
@@ -76,9 +73,10 @@ def build_markdown_notification(
|
||||
:return: Markdown 文本
|
||||
"""
|
||||
parts = [
|
||||
"## <font color=\"warning\">API 接口参数变更通知</font>",
|
||||
f"**修改人:** {push_user}",
|
||||
f"**修改时间:** {push_time}",
|
||||
"# API参数变更通知",
|
||||
f"- **变更类型:** 修改参数",
|
||||
f"- **修改人:** {push_user}",
|
||||
f"- **修改时间:** {push_time}",
|
||||
"",
|
||||
]
|
||||
|
||||
@@ -87,27 +85,17 @@ def build_markdown_notification(
|
||||
changed_reports = [r for r in reports if not r.is_new_endpoint and not r.is_removed_endpoint]
|
||||
removed_reports = [r for r in reports if r.is_removed_endpoint]
|
||||
|
||||
if new_reports:
|
||||
controllers = sorted({r.controller_class for r in new_reports})
|
||||
parts.append(f"### <font color=\"info\">新增 Controller</font> `{', '.join(controllers)}`")
|
||||
for report in new_reports:
|
||||
parts.append(_format_endpoint_block(report))
|
||||
parts.append("")
|
||||
for report in new_reports:
|
||||
parts.append(_format_endpoint_block(report))
|
||||
parts.append("")
|
||||
|
||||
if changed_reports:
|
||||
parts.append("### <font color=\"warning\">接口参数变更</font>")
|
||||
for report in changed_reports:
|
||||
parts.append(_format_endpoint_block(report))
|
||||
parts.append("")
|
||||
for report in changed_reports:
|
||||
parts.append(_format_endpoint_block(report))
|
||||
parts.append("")
|
||||
|
||||
if removed_reports:
|
||||
parts.append("### <font color=\"warning\">已删除接口</font>")
|
||||
for report in removed_reports:
|
||||
parts.append(_format_endpoint_block(report))
|
||||
parts.append("")
|
||||
for report in removed_reports:
|
||||
parts.append(_format_endpoint_block(report))
|
||||
parts.append("")
|
||||
|
||||
if llm_summary:
|
||||
cleaned = llm_summary.strip()
|
||||
@@ -226,3 +214,49 @@ def send_parameter_change_notification(
|
||||
if sent > 0:
|
||||
print(f"总共发送 {sent} 条通知到企业微信")
|
||||
return sent
|
||||
|
||||
|
||||
def build_path_change_markdown(
|
||||
old_uri: str,
|
||||
new_uri: str,
|
||||
change_type: str,
|
||||
push_user: str,
|
||||
push_time: str,
|
||||
file_name: str,
|
||||
) -> str:
|
||||
"""构建 API路径变更通知,匹配 model1.md 模板。"""
|
||||
parts = [
|
||||
"# API路径变更通知",
|
||||
f"- **变更类型:** {change_type}",
|
||||
f"- **修改人:** {push_user}",
|
||||
f"- **修改时间:** {push_time}",
|
||||
f"- **全路径类名:** {file_name}",
|
||||
"",
|
||||
"---",
|
||||
"",
|
||||
"## URI变更详情",
|
||||
"",
|
||||
"---",
|
||||
"",
|
||||
"| 项目 | 路径 |",
|
||||
"|------|------|",
|
||||
f"| 原路径 | `{old_uri if old_uri else '-'}` |",
|
||||
f"| 新路径 | `{new_uri if new_uri else '已删除'}` |",
|
||||
"",
|
||||
"---",
|
||||
]
|
||||
return "\n".join(parts).strip()
|
||||
|
||||
|
||||
def send_path_change_notification(
|
||||
webhook_url: str,
|
||||
old_uri: str,
|
||||
new_uri: str,
|
||||
change_type: str,
|
||||
push_user: str,
|
||||
push_time: str,
|
||||
file_name: str,
|
||||
) -> bool:
|
||||
"""发送路径变更通知。"""
|
||||
md = build_path_change_markdown(old_uri, new_uri, change_type, push_user, push_time, file_name)
|
||||
return _post_wecom_markdown(webhook_url, md)
|
||||
|
||||
Reference in New Issue
Block a user