@zhuxb-clouds/ai-code-review 1.3.0 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -10
- package/bin/cli.mjs +9 -8
- package/bin/hook.mjs +19 -32
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -19,10 +19,10 @@
|
|
|
19
19
|
## 🛠️ 技术架构
|
|
20
20
|
|
|
21
21
|
```
|
|
22
|
-
git commit → Husky (commit-msg) → ai-review-hook → AI API (OpenAI/DeepSeek)
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
git commit → Husky (prepare-commit-msg) → ai-review-hook → AI API (OpenAI/DeepSeek)
|
|
23
|
+
↓
|
|
24
|
+
✅ 通过:自动填充 Commit Message
|
|
25
|
+
❌ 失败:拦截提交并输出建议
|
|
26
26
|
```
|
|
27
27
|
|
|
28
28
|
---
|
|
@@ -93,7 +93,7 @@ git commit
|
|
|
93
93
|
```
|
|
94
94
|
your-project/
|
|
95
95
|
├── .husky/
|
|
96
|
-
│ └── commit-msg
|
|
96
|
+
│ └── prepare-commit-msg # Git Hook(自动创建)
|
|
97
97
|
├── .env # API Key(自己创建,不要提交!)
|
|
98
98
|
├── .env.example # 配置示例(自动创建)
|
|
99
99
|
├── .reviewignore # AI 审查忽略文件(可选)
|
|
@@ -169,14 +169,15 @@ npx ai-review setup
|
|
|
169
169
|
npx ai-review help
|
|
170
170
|
```
|
|
171
171
|
|
|
172
|
-
###
|
|
172
|
+
### 跳过 AI Review
|
|
173
173
|
|
|
174
174
|
```bash
|
|
175
|
-
#
|
|
176
|
-
git commit
|
|
175
|
+
# 使用 -m 参数时自动跳过 AI 生成(直接使用你的消息)
|
|
176
|
+
git commit -m "feat: your message"
|
|
177
177
|
|
|
178
|
-
#
|
|
179
|
-
git
|
|
178
|
+
# merge/squash/amend 提交也会自动跳过
|
|
179
|
+
git merge feature-branch
|
|
180
|
+
git commit --amend
|
|
180
181
|
```
|
|
181
182
|
|
|
182
183
|
---
|
package/bin/cli.mjs
CHANGED
|
@@ -25,9 +25,10 @@ const command = process.argv[2];
|
|
|
25
25
|
const HOOK_CONTENT = `#!/bin/sh
|
|
26
26
|
|
|
27
27
|
# AI Code Review Hook
|
|
28
|
-
# 使用 commit-msg hook 以支持 --no-verify 跳过
|
|
29
28
|
# $1: 提交消息文件路径
|
|
30
|
-
|
|
29
|
+
# $2: 提交来源 (message, template, merge, squash, commit)
|
|
30
|
+
# 当使用 git commit -m "xxx" 时,$2 为 "message",自动跳过 AI 生成
|
|
31
|
+
npx ai-review-hook "$1" "$2"
|
|
31
32
|
`;
|
|
32
33
|
|
|
33
34
|
const ENV_EXAMPLE = `# AI 提供商选择 (openai / deepseek)
|
|
@@ -117,17 +118,17 @@ function setupHook() {
|
|
|
117
118
|
fs.mkdirSync(huskyDir, { recursive: true });
|
|
118
119
|
}
|
|
119
120
|
|
|
120
|
-
// 创建 commit-msg hook
|
|
121
|
-
const hookPath = path.join(huskyDir, "commit-msg");
|
|
121
|
+
// 创建 prepare-commit-msg hook
|
|
122
|
+
const hookPath = path.join(huskyDir, "prepare-commit-msg");
|
|
122
123
|
fs.writeFileSync(hookPath, HOOK_CONTENT);
|
|
123
124
|
fs.chmodSync(hookPath, "755");
|
|
124
|
-
console.log("✅ 创建 Git Hook: .husky/commit-msg");
|
|
125
|
+
console.log("✅ 创建 Git Hook: .husky/prepare-commit-msg");
|
|
125
126
|
|
|
126
|
-
// 删除旧的
|
|
127
|
-
const oldHookPath = path.join(huskyDir, "
|
|
127
|
+
// 删除旧的 commit-msg hook(如果存在)
|
|
128
|
+
const oldHookPath = path.join(huskyDir, "commit-msg");
|
|
128
129
|
if (fs.existsSync(oldHookPath)) {
|
|
129
130
|
fs.unlinkSync(oldHookPath);
|
|
130
|
-
console.log("🗑️ 删除旧的 Hook: .husky/
|
|
131
|
+
console.log("🗑️ 删除旧的 Hook: .husky/commit-msg");
|
|
131
132
|
}
|
|
132
133
|
|
|
133
134
|
// 创建 .env.example
|
package/bin/hook.mjs
CHANGED
|
@@ -259,38 +259,25 @@ function filterDiff(diff, ignorePatterns) {
|
|
|
259
259
|
}
|
|
260
260
|
|
|
261
261
|
const commitMsgFile = process.argv[2];
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
.split("\n")
|
|
282
|
-
.filter((line) => !line.startsWith("#") && line.trim());
|
|
283
|
-
return meaningfulLines.length > 0;
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
// 如果是 merge 提交或已有 message,跳过处理
|
|
287
|
-
if (isMergeCommit()) {
|
|
288
|
-
console.log("ℹ️ 跳过 AI Review(merge 提交)");
|
|
289
|
-
process.exit(0);
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
if (hasExistingMessage()) {
|
|
293
|
-
logVerbose("检测到已有 commit message,跳过 AI 生成");
|
|
262
|
+
const commitSource = process.argv[3]; // message, template, merge, squash, commit
|
|
263
|
+
|
|
264
|
+
// 检查是否应该跳过 AI Review
|
|
265
|
+
// commitSource 说明:
|
|
266
|
+
// - "message": 使用 -m 或 -F 提供了消息
|
|
267
|
+
// - "template": 使用了模板
|
|
268
|
+
// - "merge": merge 提交
|
|
269
|
+
// - "squash": squash 提交
|
|
270
|
+
// - "commit": 使用 -c/-C/--amend
|
|
271
|
+
|
|
272
|
+
// 如果使用了 -m 提供消息,或者是 merge/squash/amend,跳过 AI 生成
|
|
273
|
+
if (["message", "merge", "squash", "commit"].includes(commitSource)) {
|
|
274
|
+
const reasons = {
|
|
275
|
+
message: "使用了 -m 参数",
|
|
276
|
+
merge: "merge 提交",
|
|
277
|
+
squash: "squash 提交",
|
|
278
|
+
commit: "amend 提交",
|
|
279
|
+
};
|
|
280
|
+
console.log(`ℹ️ 跳过 AI Review(${reasons[commitSource] || commitSource})`);
|
|
294
281
|
process.exit(0);
|
|
295
282
|
}
|
|
296
283
|
|