@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 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
- ✅ 通过:自动填充 Commit Message
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 # Git Hook(自动创建)
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
- # 跳过 AI 审查(紧急情况)
176
- git commit --no-verify -m "hotfix: urgent fix"
175
+ # 使用 -m 参数时自动跳过 AI 生成(直接使用你的消息)
176
+ git commit -m "feat: your message"
177
177
 
178
- # -m 提交时仍会进行审查,但会使用你提供的消息
179
- git commit -m "your message"
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
- npx ai-review-hook "$1"
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(支持 --no-verify 跳过)
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
- // 删除旧的 prepare-commit-msg hook(如果存在)
127
- const oldHookPath = path.join(huskyDir, "prepare-commit-msg");
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/prepare-commit-msg");
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
- // 检查是否是 merge 提交(通过检查 MERGE_HEAD 文件)
264
- function isMergeCommit() {
265
- try {
266
- const gitDir = execSync("git rev-parse --git-dir", { encoding: "utf-8" }).trim();
267
- return fs.existsSync(path.join(gitDir, "MERGE_HEAD"));
268
- } catch {
269
- return false;
270
- }
271
- }
272
-
273
- // 检查 commit message 是否已经有内容(非模板)
274
- function hasExistingMessage() {
275
- if (!commitMsgFile || !fs.existsSync(commitMsgFile)) {
276
- return false;
277
- }
278
- const content = fs.readFileSync(commitMsgFile, "utf-8");
279
- // 过滤掉注释行和空行
280
- const meaningfulLines = content
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
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zhuxb-clouds/ai-code-review",
3
- "version": "1.3.0",
3
+ "version": "1.3.1",
4
4
  "description": "基于 OpenAI API 的 Git Hooks 集成方案,自动代码审查并生成 Conventional Commits 提交信息",
5
5
  "type": "module",
6
6
  "bin": {