This commit is contained in:
@@ -250,6 +250,7 @@ def compare_endpoints(
|
|||||||
matched_added: Set[str] = set()
|
matched_added: Set[str] = set()
|
||||||
|
|
||||||
# 1. HTTP 方法变更检测(uri + controller + method_name 相同,但 method 不同)
|
# 1. HTTP 方法变更检测(uri + controller + method_name 相同,但 method 不同)
|
||||||
|
# 如果同时有参数变更,生成两条独立报告(方法变更 + 参数变更),互不干扰
|
||||||
for r_key, r_ep in unmatched_removed:
|
for r_key, r_ep in unmatched_removed:
|
||||||
for a_key, a_ep in unmatched_added:
|
for a_key, a_ep in unmatched_added:
|
||||||
if a_key in matched_added:
|
if a_key in matched_added:
|
||||||
@@ -260,6 +261,7 @@ def compare_endpoints(
|
|||||||
and r_ep.method_name == a_ep.method_name
|
and r_ep.method_name == a_ep.method_name
|
||||||
and r_ep.http_method != a_ep.http_method
|
and r_ep.http_method != a_ep.http_method
|
||||||
):
|
):
|
||||||
|
# 先生成纯方法变更报告
|
||||||
reports.append(
|
reports.append(
|
||||||
EndpointChangeReport(
|
EndpointChangeReport(
|
||||||
uri=a_ep.uri,
|
uri=a_ep.uri,
|
||||||
@@ -271,12 +273,25 @@ def compare_endpoints(
|
|||||||
old_http_method=r_ep.http_method,
|
old_http_method=r_ep.http_method,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
# 再检测参数变更,如果有则额外生成一条独立的参数变更报告
|
||||||
|
param_changes = compare_parameters(r_ep.parameters, a_ep.parameters)
|
||||||
|
if param_changes:
|
||||||
|
reports.append(
|
||||||
|
EndpointChangeReport(
|
||||||
|
uri=a_ep.uri,
|
||||||
|
http_method=a_ep.http_method,
|
||||||
|
controller_class=a_ep.controller_class,
|
||||||
|
method_name=a_ep.method_name,
|
||||||
|
source_file=a_ep.source_file,
|
||||||
|
parameter_changes=param_changes,
|
||||||
|
)
|
||||||
|
)
|
||||||
matched_removed.add(r_key)
|
matched_removed.add(r_key)
|
||||||
matched_added.add(a_key)
|
matched_added.add(a_key)
|
||||||
break
|
break
|
||||||
|
|
||||||
# 2. URI 路径变更检测(method + controller + method_name 相同,但 uri 不同)
|
# 2. URI 路径变更检测(method + controller + method_name 相同,但 uri 不同)
|
||||||
# 同时检测参数变更,即使 URI 改变也记录参数差异
|
# 如果同时有参数变更,生成两条独立报告(路径变更 + 参数变更),互不干扰
|
||||||
for r_key, r_ep in unmatched_removed:
|
for r_key, r_ep in unmatched_removed:
|
||||||
if r_key in matched_removed:
|
if r_key in matched_removed:
|
||||||
continue
|
continue
|
||||||
@@ -289,7 +304,7 @@ def compare_endpoints(
|
|||||||
and r_ep.method_name == a_ep.method_name
|
and r_ep.method_name == a_ep.method_name
|
||||||
and r_ep.uri != a_ep.uri
|
and r_ep.uri != a_ep.uri
|
||||||
):
|
):
|
||||||
param_changes = compare_parameters(r_ep.parameters, a_ep.parameters)
|
# 先生成纯路径变更报告
|
||||||
reports.append(
|
reports.append(
|
||||||
EndpointChangeReport(
|
EndpointChangeReport(
|
||||||
uri=a_ep.uri,
|
uri=a_ep.uri,
|
||||||
@@ -299,6 +314,18 @@ def compare_endpoints(
|
|||||||
source_file=a_ep.source_file,
|
source_file=a_ep.source_file,
|
||||||
is_renamed_endpoint=True,
|
is_renamed_endpoint=True,
|
||||||
old_uri=r_ep.uri,
|
old_uri=r_ep.uri,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
# 再检测参数变更,如果有则额外生成一条独立的参数变更报告
|
||||||
|
param_changes = compare_parameters(r_ep.parameters, a_ep.parameters)
|
||||||
|
if param_changes:
|
||||||
|
reports.append(
|
||||||
|
EndpointChangeReport(
|
||||||
|
uri=a_ep.uri,
|
||||||
|
http_method=a_ep.http_method,
|
||||||
|
controller_class=a_ep.controller_class,
|
||||||
|
method_name=a_ep.method_name,
|
||||||
|
source_file=a_ep.source_file,
|
||||||
parameter_changes=param_changes,
|
parameter_changes=param_changes,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -79,13 +79,14 @@ def build_markdown_notification(
|
|||||||
method_changed_reports = [r for r in reports if r.is_method_changed]
|
method_changed_reports = [r for r in reports if r.is_method_changed]
|
||||||
renamed_reports = [r for r in reports if r.is_renamed_endpoint]
|
renamed_reports = [r for r in reports if r.is_renamed_endpoint]
|
||||||
new_reports = [r for r in reports if r.is_new_endpoint]
|
new_reports = [r for r in reports if r.is_new_endpoint]
|
||||||
# 参数变更报告:包含普通参数变更 + 路径变更时同时修改了参数的情况
|
# 参数变更报告:只包含「URI/方法未变,仅参数变化」的报告
|
||||||
|
# 路径变更 + 参数变更、方法变更 + 参数变更 场景已在上层 comparator 中拆分为独立报告
|
||||||
changed_reports = [
|
changed_reports = [
|
||||||
r for r in reports
|
r for r in reports
|
||||||
if not r.is_new_endpoint
|
if not r.is_new_endpoint
|
||||||
and not r.is_removed_endpoint
|
and not r.is_removed_endpoint
|
||||||
|
and not r.is_renamed_endpoint
|
||||||
and not r.is_method_changed
|
and not r.is_method_changed
|
||||||
# 注意:不再排除 is_renamed_endpoint,允许「路径+参数」同时变更时发参数通知
|
|
||||||
]
|
]
|
||||||
removed_reports = [r for r in reports if r.is_removed_endpoint]
|
removed_reports = [r for r in reports if r.is_removed_endpoint]
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
# API参数变更通知
|
# 【API参数变更通知】
|
||||||
|
|
||||||
- **变更类型:** {新增接口 / 修改参数 / 删除接口}
|
- **变更类型:** {新增接口 / 修改参数 / 删除接口}
|
||||||
- **URI:** {Method} {URI}
|
- **URI:** {Method} {URI}
|
||||||
|
|||||||
Reference in New Issue
Block a user