This commit is contained in:
@@ -7,12 +7,13 @@ from __future__ import annotations
|
|||||||
|
|
||||||
import re
|
import re
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Dict, List, Optional, Union
|
from typing import Dict, List, Optional
|
||||||
|
|
||||||
import javalang
|
import javalang
|
||||||
from javalang.tree import (
|
from javalang.tree import (
|
||||||
Annotation,
|
Annotation,
|
||||||
ClassDeclaration,
|
ClassDeclaration,
|
||||||
|
ElementValuePair,
|
||||||
FieldDeclaration,
|
FieldDeclaration,
|
||||||
FormalParameter,
|
FormalParameter,
|
||||||
Literal,
|
Literal,
|
||||||
@@ -32,14 +33,18 @@ def _ann_simple_name(ann: Annotation) -> str:
|
|||||||
|
|
||||||
|
|
||||||
def _literal_str(node) -> str:
|
def _literal_str(node) -> str:
|
||||||
"""从 Literal 节点提取字符串值。"""
|
"""从 AST 节点提取字符串或布尔值。"""
|
||||||
if node is None:
|
if node is None:
|
||||||
return ""
|
return ""
|
||||||
if isinstance(node, Literal):
|
if isinstance(node, Literal):
|
||||||
v = node.value or ""
|
v = node.value
|
||||||
return str(v).strip('"').strip("'")
|
if isinstance(v, bool):
|
||||||
|
return str(v).lower()
|
||||||
|
return str(v or "").strip('"').strip("'")
|
||||||
if isinstance(node, MemberReference):
|
if isinstance(node, MemberReference):
|
||||||
return node.member
|
return node.member
|
||||||
|
if isinstance(node, bool):
|
||||||
|
return str(node).lower()
|
||||||
return str(node).strip('"').strip("'")
|
return str(node).strip('"').strip("'")
|
||||||
|
|
||||||
|
|
||||||
@@ -52,12 +57,12 @@ def _collect_ann_members(ann: Annotation) -> Dict[str, str]:
|
|||||||
el = ann.element
|
el = ann.element
|
||||||
if el is None:
|
if el is None:
|
||||||
return members
|
return members
|
||||||
if isinstance(el, list):
|
if isinstance(el, ElementValuePair):
|
||||||
for item in el:
|
|
||||||
if hasattr(item, "name") and hasattr(item, "value"):
|
|
||||||
members[item.name] = _literal_str(item.value)
|
|
||||||
elif hasattr(el, "name") and hasattr(el, "value"):
|
|
||||||
members[el.name] = _literal_str(el.value)
|
members[el.name] = _literal_str(el.value)
|
||||||
|
elif isinstance(el, list):
|
||||||
|
for item in el:
|
||||||
|
if isinstance(item, ElementValuePair):
|
||||||
|
members[item.name] = _literal_str(item.value)
|
||||||
else:
|
else:
|
||||||
members["value"] = _literal_str(el)
|
members["value"] = _literal_str(el)
|
||||||
return members
|
return members
|
||||||
@@ -348,15 +353,15 @@ def parse_controller_files(
|
|||||||
:param file_contents: {文件路径: 源码内容}
|
:param file_contents: {文件路径: 源码内容}
|
||||||
:return: 所有端点
|
:return: 所有端点
|
||||||
"""
|
"""
|
||||||
source_dir = repo_root / source_subdir.replace("/", Path.sep)
|
source_dir = (repo_root / source_subdir).resolve()
|
||||||
parser = ControllerAstParser(repo_root, source_dir)
|
parser = ControllerAstParser(repo_root, source_dir)
|
||||||
endpoints: List[ApiEndpoint] = []
|
endpoints: List[ApiEndpoint] = []
|
||||||
|
|
||||||
for path in file_paths:
|
for path in file_paths:
|
||||||
content = file_contents.get(path)
|
norm = path.replace("\\", "/")
|
||||||
|
content = file_contents.get(norm)
|
||||||
if not content:
|
if not content:
|
||||||
continue
|
continue
|
||||||
norm = path.replace("\\", "/")
|
|
||||||
endpoints.extend(parser.parse_file_content(content, norm))
|
endpoints.extend(parser.parse_file_content(content, norm))
|
||||||
|
|
||||||
return endpoints
|
return endpoints
|
||||||
|
|||||||
@@ -130,7 +130,7 @@ def main() -> int:
|
|||||||
print("[Git] 首次提交,无可对比版本,跳过。")
|
print("[Git] 首次提交,无可对比版本,跳过。")
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
changed_files = get_changed_java_controller_files(prev_sha, commit_info.sha)
|
changed_files = [f.replace("\\", "/") for f in get_changed_java_controller_files(prev_sha, commit_info.sha)]
|
||||||
if not changed_files:
|
if not changed_files:
|
||||||
print("[Git] 本次提交未变更 Controller 文件,跳过。")
|
print("[Git] 本次提交未变更 Controller 文件,跳过。")
|
||||||
return 0
|
return 0
|
||||||
|
|||||||
Reference in New Issue
Block a user