From e4eb41013c9ad167ef91c8c0ae2af137fa880707 Mon Sep 17 00:00:00 2001 From: dongzi Date: Fri, 5 Jun 2026 10:29:21 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9EAPI=E8=AF=B7=E6=B1=82?= =?UTF-8?q?=E6=96=B9=E5=BC=8F=E5=8F=98=E6=9B=B4=E9=80=9A=E7=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitea/checker/notifier.py | 64 +++++++++++++++++++++++++++----------- 1 file changed, 45 insertions(+), 19 deletions(-) diff --git a/.gitea/checker/notifier.py b/.gitea/checker/notifier.py index e1d3471..e273470 100644 --- a/.gitea/checker/notifier.py +++ b/.gitea/checker/notifier.py @@ -101,19 +101,17 @@ def build_markdown_notification( parts.append(path_md) parts.append("") - # 2. 修改请求方式 → 走 API路径变更通知 + # 2. 修改请求方式 → 使用独立的新模板 【API请求方式变更通知】 for report in method_changed_reports: - path_md = build_path_change_markdown( - old_uri=report.uri, - new_uri=report.uri, - change_type="修改请求方式", + method_md = build_method_change_markdown( + uri=report.uri, + old_method=report.old_http_method or "?", + new_method=report.http_method, push_user=push_user, push_time=push_time, file_name=report.source_file or report.controller_class, - old_method=report.old_http_method, - new_method=report.http_method, ) - parts.append(path_md) + parts.append(method_md) parts.append("") # 3. 修改路径 → 走 API路径变更通知 @@ -278,8 +276,6 @@ def build_path_change_markdown( push_user: str, push_time: str, file_name: str, - old_method: Optional[str] = None, - new_method: Optional[str] = None, ) -> str: """构建 API路径变更通知,完全匹配 model1.md 模板,并加强视觉区分。 @@ -305,15 +301,6 @@ def build_path_change_markdown( elif change_type == "删除接口": old_display = f"**`{old_uri}`****已删除**" new_display = "`已删除`" - elif change_type == "修改请求方式": - # 方法变更场景:展示原方法 → 新方法 - old_m = old_method or "?" - new_m = new_method or "?" - old_display = f"**`{old_uri}` **[{old_m}]**" - new_display = ( - f"**`{new_uri}` " - f"**[{old_m} → {new_m}]****请求方式变更**" - ) else: # 修改路径 old_display = f"~~`{old_uri}`~~**旧路径**" new_display = f"**`{new_uri}`****新路径**" @@ -337,6 +324,45 @@ def build_path_change_markdown( return "\n".join(parts).strip() +def build_method_change_markdown( + uri: str, + old_method: str, + new_method: str, + push_user: str, + push_time: str, + file_name: str, +) -> str: + """构建【API请求方式变更通知】独立模板。 + + 格式参考 model1.md,但专门针对 HTTP 方法变更场景设计, + 突出「原请求方式 → 新请求方式」的对比。 + """ + type_highlight = '**修改请求方式**' + class_highlight = f'**{file_name}**' + uri_highlight = f'**`{uri}`**' + old_m = f'**{old_method}**' + new_m = f'**{new_method}**' + + parts = [ + "# 【API请求方式变更通知】", + "", + f" 变更类型: {type_highlight}", + f" 全路径类名: {class_highlight}", + f" 修改人: {push_user}", + f" 修改时间: {push_time}", + "", + "---", + "", + "#### 【请求方式变更详情】", + f"- **URI:** {uri_highlight}", + f"- **原请求方式:** {old_m}", + f"- **新请求方式:** {new_m} ← **请求方式已变更**", + "", + "---", + ] + return "\n".join(parts).strip() + + def send_path_change_notification( webhook_url: str, old_uri: str,