best-review 0.5.7 → 0.5.9
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 +45 -52
- package/dist/best-review.cjs +228 -225
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
- 支持用户级规则、共享 `extends` 规则包和项目级 `skills/` 审查增强。
|
|
11
11
|
- 默认执行置信度过滤、去重、validation 复核,减少泛泛建议和误报。
|
|
12
12
|
- 支持显式自动修复严重风险,先生成 unified diff,并通过 `git apply --check` 后才写入。
|
|
13
|
-
- 生成本地 JSON 报告;本地 `review`
|
|
13
|
+
- 生成本地 JSON 报告;本地 `review` 配置历史仓库后会自动归档,`review-mr` 只回评 MR。
|
|
14
14
|
|
|
15
15
|
## 快速开始
|
|
16
16
|
|
|
@@ -41,7 +41,7 @@ best-review init --provider openai
|
|
|
41
41
|
best-review review
|
|
42
42
|
```
|
|
43
43
|
|
|
44
|
-
`best-review init` 会以选项式流程写入用户级 `~/.best-review/config.json
|
|
44
|
+
`best-review init` 会以选项式流程写入用户级 `~/.best-review/config.json`,并提示是否把 `GITLAB_TOKEN` 写入同一个用户级配置文件;直接回车可跳过。
|
|
45
45
|
|
|
46
46
|
## 常用命令
|
|
47
47
|
|
|
@@ -56,6 +56,11 @@ best-review review --base main
|
|
|
56
56
|
best-review review --branch .
|
|
57
57
|
best-review review --branch feature/login --base main
|
|
58
58
|
|
|
59
|
+
# 审查单个 commit 或连续多个 commit
|
|
60
|
+
best-review review --commit HEAD
|
|
61
|
+
best-review review --commit abc1234
|
|
62
|
+
best-review review --commit-range HEAD~3..HEAD
|
|
63
|
+
|
|
59
64
|
# 只审查指定文件的 Git 变更
|
|
60
65
|
best-review review --files src/auth.ts
|
|
61
66
|
best-review review --files src/auth.ts,src/user.ts --base main
|
|
@@ -93,7 +98,8 @@ best-review review --fix-severity critical,high --fix-dry-run
|
|
|
93
98
|
best-review review --fix-critical --fix-max-issues 3 --fix-patch-file ~/.best-review/fix.patch
|
|
94
99
|
|
|
95
100
|
# GitLab MR 远程审查
|
|
96
|
-
|
|
101
|
+
br init GITLAB_TOKEN
|
|
102
|
+
best-review review-mr https://gitlab.example.com/group/project/-/merge_requests/123
|
|
97
103
|
|
|
98
104
|
# 查看内置资产和执行器
|
|
99
105
|
best-review agents
|
|
@@ -154,6 +160,9 @@ POST <llm.baseUrl>/chat/completions
|
|
|
154
160
|
"apiKey": "<your-api-key>",
|
|
155
161
|
"model": "deepseek-v4-flash"
|
|
156
162
|
},
|
|
163
|
+
"gitlab": {
|
|
164
|
+
"token": "<your-gitlab-token>"
|
|
165
|
+
},
|
|
157
166
|
"executors": {
|
|
158
167
|
"openai-compatible-api": {
|
|
159
168
|
"review": { "concurrency": 2 },
|
|
@@ -187,6 +196,9 @@ POST <llm.baseUrl>/chat/completions
|
|
|
187
196
|
"apiKey": "<your-api-key>",
|
|
188
197
|
"model": "deepseek-v4-flash"
|
|
189
198
|
},
|
|
199
|
+
"gitlab": {
|
|
200
|
+
"token": "<your-gitlab-token>"
|
|
201
|
+
},
|
|
190
202
|
"executors": {
|
|
191
203
|
"deepseek-api": {
|
|
192
204
|
"review": { "concurrency": 2 },
|
|
@@ -253,12 +265,13 @@ POST <llm.baseUrl>/chat/completions
|
|
|
253
265
|
```bash
|
|
254
266
|
best-review config
|
|
255
267
|
best-review init
|
|
268
|
+
br init GITLAB_TOKEN
|
|
256
269
|
best-review config show
|
|
257
270
|
best-review config edit
|
|
258
271
|
best-review doctor
|
|
259
272
|
```
|
|
260
273
|
|
|
261
|
-
`best-review init` 用来初始化或更新 `~/.best-review/config.json`;`best-review config` 会用当前用户级配置做一次简化诊断;`best-review doctor` 输出同一套诊断结果,适合在本地或 CI 中确认当前机器是否可以直接执行 review。
|
|
274
|
+
`best-review init` 用来初始化或更新 `~/.best-review/config.json`;`br init GITLAB_TOKEN` 只配置用户级 `gitlab.token`,不会要求重新填写模型服务。`best-review config` 会用当前用户级配置做一次简化诊断;`best-review doctor` 输出同一套诊断结果,适合在本地或 CI 中确认当前机器是否可以直接执行 review。
|
|
262
275
|
|
|
263
276
|
## 审查流程
|
|
264
277
|
|
|
@@ -282,6 +295,8 @@ flowchart LR
|
|
|
282
295
|
关键行为:
|
|
283
296
|
|
|
284
297
|
- `filterReviewableDiffs()` 默认跳过二进制、生成物、文档和命中排除规则的文件。
|
|
298
|
+
- 本地 review 支持未提交变更、`--base/--head`、`--branch`、`--commit`、`--commit-range`、`--files` 和 `--full`;互斥或不完整的参数组合会在进入 pipeline 前直接拒绝。
|
|
299
|
+
- `--commit <ref>` 等价于比较 `<ref>^` 和 `<ref>`;`--commit-range <oldest>..<newest>` 会包含两端 commit,要求 `<oldest>` 是 `<newest>` 的祖先。
|
|
285
300
|
- 本地 review 会补充变更文件全文和一层相对依赖上下文,避免模型只看 diff。
|
|
286
301
|
- diff 输入默认压缩,只保留 hunk 行号、变更行和少量上下文。
|
|
287
302
|
- 默认是多 Agent 独立审查;设置 `BEST_REVIEW_MULTI_AGENT=false` 可把多个专业 Agent 合并成一次快速审查。
|
|
@@ -355,18 +370,23 @@ best-review extends remove https://github.com/org/best-review-rules.git
|
|
|
355
370
|
`review-mr` 会直接读取 GitLab MR diff 和远程文件内容,运行同一套 pipeline,并默认启用 GitLab Reporting。
|
|
356
371
|
|
|
357
372
|
```bash
|
|
358
|
-
|
|
373
|
+
br init GITLAB_TOKEN
|
|
359
374
|
|
|
360
375
|
best-review review-mr https://gitlab.example.com/group/project/-/merge_requests/123
|
|
361
376
|
best-review review-mr <mr-url> --agent security-scan --log-steps
|
|
362
377
|
best-review review-mr <mr-url> --executor deepseek-api --model deepseek-v4-flash
|
|
363
378
|
```
|
|
364
379
|
|
|
380
|
+
如果运行 `review-mr` 时当前环境和用户级配置都没有 `GITLAB_TOKEN`,CLI 会在交互式终端中提示填写并写入 `~/.best-review/config.json`;直接回车会取消本次 MR 审查。CI 中仍可通过 `export GITLAB_TOKEN=<token>` 或平台变量注入。
|
|
381
|
+
|
|
382
|
+
`review-mr` 启动前会先校验内置 GitLab 配置是否存在:`BEST_REVIEW_HISTORY_REMOTE`、`BEST_REVIEW_HISTORY_BRANCH`、`GITLAB_HOST`、`BEST_REVIEW_HISTORY_USER_TOKEN`。其中 `BEST_REVIEW_HISTORY_USER_TOKEN` 只用于读取 MR 和解析 GitLab 用户;`GITLAB_TOKEN` 只用于向 MR 发布 discussion。
|
|
383
|
+
|
|
365
384
|
可选变量:
|
|
366
385
|
|
|
367
386
|
| 变量 | 说明 |
|
|
368
387
|
| --- | --- |
|
|
369
|
-
| `
|
|
388
|
+
| `BEST_REVIEW_HISTORY_USER_TOKEN` | 读取 MR 和解析 GitLab 用户的内置 token |
|
|
389
|
+
| `GITLAB_TOKEN` | 发布 MR discussion 的 token,需要用户自行配置 |
|
|
370
390
|
| `GITLAB_HOST` | GitLab API host 覆盖值;可传 `https://gitlab.example.com` 或完整 `/api/v4` |
|
|
371
391
|
| `BEST_REVIEW_GITLAB_ENABLED` | 本地 `review` 模式下设置为 `true` 时启用 GitLab Reporting |
|
|
372
392
|
| `GITLAB_PROJECT_ID` / `CI_PROJECT_ID` | 非 `review-mr` 模式下用于定位项目 |
|
|
@@ -457,85 +477,58 @@ best-review review --base origin/main --json
|
|
|
457
477
|
|
|
458
478
|
## Reporting
|
|
459
479
|
|
|
460
|
-
每次 review
|
|
480
|
+
每次 `best-review review` 都会保存一份本地 JSON 报告,默认目录:
|
|
461
481
|
|
|
462
482
|
```text
|
|
463
483
|
~/.best-review/reports/
|
|
464
484
|
```
|
|
465
485
|
|
|
466
|
-
|
|
486
|
+
报告包含仓库信息、模型、风险结论、质量评分、最终问题和 diff 摘要。默认不保存完整 diff。
|
|
467
487
|
|
|
468
|
-
|
|
488
|
+
如果想把本地 review 结果归档到 Git 仓库,配置自己的仓库地址即可启用历史归档:
|
|
469
489
|
|
|
470
|
-
```
|
|
490
|
+
```bash
|
|
471
491
|
BEST_REVIEW_HISTORY_REMOTE=git@git.example.com:team/review-history.git
|
|
492
|
+
BEST_REVIEW_HISTORY_BRANCH=review-log
|
|
472
493
|
```
|
|
473
494
|
|
|
474
|
-
|
|
495
|
+
如需临时关闭历史归档,可以设置:
|
|
496
|
+
|
|
497
|
+
```bash
|
|
498
|
+
BEST_REVIEW_HISTORY=false
|
|
499
|
+
```
|
|
500
|
+
|
|
501
|
+
上传后的文件会按项目和 GitLab 用户分组:
|
|
475
502
|
|
|
476
503
|
```text
|
|
477
504
|
projects/<group>/<project>/<gitlab-user>/<timestamp>-<run-id>.json
|
|
478
505
|
```
|
|
479
506
|
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
历史归档显式开启且上传成功后,本地 JSON 会被删除,避免长期占用用户电脑空间。如果历史上传失败,或主 Reporting 上报失败,本地 JSON 会保留,方便排查或手动处理。
|
|
507
|
+
历史归档只上传 `best-review review` 的本地结果;`best-review review-mr` 不会上传到历史仓库。
|
|
483
508
|
|
|
484
|
-
|
|
509
|
+
上传成功后,本地 JSON 会被删除,避免长期占用磁盘;上传失败时会保留本地文件,方便排查。
|
|
485
510
|
|
|
486
|
-
|
|
511
|
+
也可以通过用户级 `~/.best-review/config.json` 配置:
|
|
487
512
|
|
|
488
513
|
```json
|
|
489
514
|
{
|
|
490
515
|
"reporting": {
|
|
491
|
-
"enabled": true,
|
|
492
|
-
"url": "https://efficiency.example.com/api/ai-review/usages",
|
|
493
|
-
"token": "replace-with-token",
|
|
494
|
-
"includeDiffs": false,
|
|
495
|
-
"failOnError": false,
|
|
496
|
-
"historyEnabled": false,
|
|
497
516
|
"historyRemote": "git@git.example.com:team/review-history.git",
|
|
498
517
|
"historyBranch": "review-log"
|
|
499
518
|
}
|
|
500
519
|
}
|
|
501
520
|
```
|
|
502
521
|
|
|
503
|
-
|
|
522
|
+
`historyEnabled` 仍可显式设置为 `true`;配置了 `historyRemote` 时不再需要额外开启。
|
|
523
|
+
|
|
524
|
+
如果还需要把报告 POST 到内部效能系统,再配置 Reporting URL:
|
|
504
525
|
|
|
505
526
|
```bash
|
|
506
|
-
BEST_REVIEW_REPORT_DIR=$HOME/.best-review/reports
|
|
507
527
|
BEST_REVIEW_REPORT_URL=https://efficiency.example.com/api/ai-review/usages
|
|
508
528
|
BEST_REVIEW_REPORT_TOKEN=replace-with-token
|
|
509
|
-
BEST_REVIEW_REPORT_INCLUDE_DIFFS=false
|
|
510
|
-
BEST_REVIEW_REPORT_FAIL_ON_ERROR=false
|
|
511
|
-
```
|
|
512
|
-
|
|
513
|
-
审查历史仓库相关环境变量:
|
|
514
|
-
|
|
515
|
-
```bash
|
|
516
|
-
# 显式开启本地 review 历史归档;默认关闭
|
|
517
|
-
BEST_REVIEW_HISTORY=true
|
|
518
|
-
|
|
519
|
-
# 如需覆盖配置并关闭历史归档
|
|
520
|
-
BEST_REVIEW_HISTORY=false
|
|
521
|
-
|
|
522
|
-
# 审查历史仓库地址,启用历史归档时必须显式设置
|
|
523
|
-
BEST_REVIEW_HISTORY_REMOTE=git@git.example.com:team/review-history.git
|
|
524
|
-
|
|
525
|
-
# 审查历史分支;默认 review-log
|
|
526
|
-
BEST_REVIEW_HISTORY_BRANCH=review-log
|
|
527
|
-
|
|
528
|
-
# 覆盖临时 clone 目录;默认在 ~/.best-review/tmp 下创建并自动清理
|
|
529
|
-
BEST_REVIEW_HISTORY_TMP_DIR=$HOME/.best-review/tmp
|
|
530
|
-
|
|
531
|
-
# 显式指定归档使用的 GitLab 用户名
|
|
532
|
-
BEST_REVIEW_GITLAB_USER=alice
|
|
533
|
-
|
|
534
|
-
# HTTPS 远端认证可使用 GITLAB_TOKEN;如需覆盖 Git 用户名可单独设置
|
|
535
|
-
BEST_REVIEW_HISTORY_GIT_USERNAME=alice
|
|
536
529
|
```
|
|
537
530
|
|
|
538
|
-
|
|
531
|
+
默认上报失败不会阻断 review。CI 里想让上报失败直接失败,可以设置 `BEST_REVIEW_REPORT_FAIL_ON_ERROR=true`。
|
|
539
532
|
|
|
540
533
|
## 审查质量评测
|
|
541
534
|
|