-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
54 lines (45 loc) · 1.79 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# from analyzers.ast_parser import ASTAnalyzer
# from rules import style, security
# def code_review(file_path):
# # AST解析
# with open(file_path) as f:
# tree = ast.parse(f.read())
# # 执行静态分析
# analyzer = ASTAnalyzer()
# analyzer.visit(tree)
# # 应用规则检查
# style_violations = StyleRules.check_naming_convention(tree)
# security_issues = SecurityRules.check_injection(tree)
# # AI增强审查
# if config['ai']['enable']:
# ai_reviewer = AICodeReviewer(config['ai']['api_key'])
# ai_suggestions = ai_reviewer.get_optimization_suggestion(code_snippet)
# # 生成报告
# generate_report({
# 'static_analysis': analyzer.findings,
# 'style_violations': style_violations,
# 'ai_suggestions': ai_suggestions
# })
import click
from ai_review.core.analyzer import CodeAnalyzer
from ai_review.core.model_adapter import AIModelHandler
@click.command()
@click.argument('file_path')
@click.option('--ai', is_flag=True, help='启用AI增强审查')
def review(file_path: str, ai: bool):
"""执行代码审查流水线"""
with open(file_path) as f:
code = f.read()
# 静态规则审查
analyzer = CodeAnalyzer(['ai_review.rules.security_rules'])
findings = analyzer.analyze(code)
# AI增强分析
if ai:
ai_handler = AIModelHandler()
ai_comment = ai_handler.get_code_review(code, {'findings': findings})
click.echo(f"\nAI审查建议:\n{ai_comment}")
# 输出格式化结果
click.echo("\n静态审查结果:")
for issue in findings:
click.secho(f"[{issue['severity'].upper()}] Line {issue['line']}: {issue['message']}",
fg='red' if issue['severity'] == 'critical' else 'yellow')