OpenCodeReview:AI 代码审查 CLI 2026 版
OpenCodeReview 用 AI 自动审查代码。检测 Bug、漏洞、代码 smell。支持 GitHub、GitLab。CI/CD 集成。
- ⭐ 850
- Python
- CLI
- AI
- MIT
- 更新于 2026-05-18
什么是 OpenCodeReview? #
OpenCodeReview 用 AI 自动审查代码。检测 Bug、漏洞、代码 smell。支持 GitHub、GitLab。CI/CD 集成。
安装 #
Python #
pip install opencode-review
desde #
cargo install opencode-review
Homebrew #
brew install opencode-review
基本用法 #
审查单个文件 #
ocr review src/main.py
审查目录 #
ocr review src/ --recursive
审查 Git PR #
ocr review --pr 123
配置文件 #
ocr.yaml #
model:
name: gpt-4
temperature: 0.5
max_tokens: 4096
rules:
- "不要引入新的依赖"
- "所有函数都要有类型注解"
- "禁止使用全局变量"
languages:
- python
- javascript
- go
exclude:
- "tests/**"
- "node_modules/**"
审查检查项 #
语法错误 #
# 被检测到的问题
def calculate(a, b):
return a / b # 除数可能为 0
安全漏洞 #
// SQL 注入风险
const query = "SELECT * FROM users WHERE id = " + userId;
db.query(query); // ocr 检测到
性能问题 #
// 低效的字符串拼接
var s string
for _, v := range items {
s += v // 每次都重新分配内存
}
CI/CD 集成 #
GitHub Actions #
- name: AI Code Review
uses: opencode-review/action@v1
with:
api-key: ${{ secrets.OPENAI_API_KEY }}
model: gpt-4
fail-on-warning: true
GitLab CI #
ocr:
stage: test
image: python:3.11
script:
- pip install opencode-review
- ocr review src/ --fail-on-warning
Jenkins #
stage('Code Review') {
agent any
steps {
sh 'pip install opencode-review'
sh 'ocr review .'
}
}
高级功能 #
自定义规则 #
# .ocr-rules.yaml
- name: 避免使用 eval
pattern: '\beval\s*\('
message: "不要使用 eval()"
severity: error
- name: 函数长度限制
pattern: 'def \w+\([^)]*\):[^\\n]{0,500}\\n'
message: "函数太长,应该拆分"
severity: warning
批量处理 #
# 处理多个 PR
ocr batch review --prs 123,124,125
生成报告 #
ocr report --format html --output review.html
集成 IDE #
VS Code #
{
"ocr.enabled": true,
"ocr.autoReview": true,
"ocr.model": "gpt-4"
}
Neovim #
require('ocr').setup({
auto_review = true,
model = "gpt-4"
})
性能调优 #
并行审查 #
ocr review src/ --parallel 4
缓存结果 #
cache:
enabled: true
ttl: 3600
常见问题 #
Q: AI 审查会误报吗?
答:会。通过人工复核和规则过滤降低误报。
Q: 支持哪些 AI 模型?
答:OpenAI、Anthropic、Google、Ollama 本地模型。
Q: 如何获取 API Key?
答:每个 LLM 提供商都有自己的 Key。
总结 #
OpenCodeReview 让「AI 驱动代码审查」落地。CI/CD 中必备工具。
参考:opencode-review.github.io 更新:2026-05-18
💬 留言讨论