From 6af9324e4b53483c6baad7495ab330e4cf460f9d Mon Sep 17 00:00:00 2001 From: dongzi Date: Wed, 3 Jun 2026 15:44:25 +0800 Subject: [PATCH] =?UTF-8?q?py=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitea/checker/controller_ast_parser.py | 29 +++++++++++++++---------- .gitea/checker/main.py | 2 +- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/.gitea/checker/controller_ast_parser.py b/.gitea/checker/controller_ast_parser.py index 2ec407d..94a69f6 100644 --- a/.gitea/checker/controller_ast_parser.py +++ b/.gitea/checker/controller_ast_parser.py @@ -7,12 +7,13 @@ from __future__ import annotations import re from pathlib import Path -from typing import Dict, List, Optional, Union +from typing import Dict, List, Optional import javalang from javalang.tree import ( Annotation, ClassDeclaration, + ElementValuePair, FieldDeclaration, FormalParameter, Literal, @@ -32,14 +33,18 @@ def _ann_simple_name(ann: Annotation) -> str: def _literal_str(node) -> str: - """从 Literal 节点提取字符串值。""" + """从 AST 节点提取字符串或布尔值。""" if node is None: return "" if isinstance(node, Literal): - v = node.value or "" - return str(v).strip('"').strip("'") + v = node.value + if isinstance(v, bool): + return str(v).lower() + return str(v or "").strip('"').strip("'") if isinstance(node, MemberReference): return node.member + if isinstance(node, bool): + return str(node).lower() return str(node).strip('"').strip("'") @@ -52,12 +57,12 @@ def _collect_ann_members(ann: Annotation) -> Dict[str, str]: el = ann.element if el is None: return members - if isinstance(el, list): - 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"): + if isinstance(el, ElementValuePair): 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: members["value"] = _literal_str(el) return members @@ -348,15 +353,15 @@ def parse_controller_files( :param file_contents: {文件路径: 源码内容} :return: 所有端点 """ - source_dir = repo_root / source_subdir.replace("/", Path.sep) + source_dir = (repo_root / source_subdir).resolve() parser = ControllerAstParser(repo_root, source_dir) endpoints: List[ApiEndpoint] = [] for path in file_paths: - content = file_contents.get(path) + norm = path.replace("\\", "/") + content = file_contents.get(norm) if not content: continue - norm = path.replace("\\", "/") endpoints.extend(parser.parse_file_content(content, norm)) return endpoints diff --git a/.gitea/checker/main.py b/.gitea/checker/main.py index b201845..2b146aa 100644 --- a/.gitea/checker/main.py +++ b/.gitea/checker/main.py @@ -130,7 +130,7 @@ def main() -> int: print("[Git] 首次提交,无可对比版本,跳过。") 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: print("[Git] 本次提交未变更 Controller 文件,跳过。") return 0