pr-truce 0.0.0-stage → 0.3.0
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/LICENSE +21 -0
- package/README.md +270 -3
- package/README.zh-CN.md +270 -0
- package/action.yml +54 -0
- package/dist/action/index.js +10501 -0
- package/dist/cli/index.js +11557 -0
- package/dist/core/index.js +10023 -0
- package/package.json +59 -6
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 pr-truce contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,270 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
3
|
+
# pr-truce
|
|
4
|
+
|
|
5
|
+
**One Must-fix list from every AI and human code review.**
|
|
6
|
+
|
|
7
|
+
Keep CodeRabbit, Gemini, Copilot and your teammates reviewing.<br>
|
|
8
|
+
pr-truce reads what each of them actually flagged, folds the noise, and tells everyone what blocks the merge.
|
|
9
|
+
|
|
10
|
+
[](https://github.com/LL333111/pr-truce/actions/workflows/ci.yml)
|
|
11
|
+
[](https://github.com/LL333111/pr-truce/releases)
|
|
12
|
+
[](#quick-start)
|
|
13
|
+
[](./LICENSE)
|
|
14
|
+
|
|
15
|
+
[Quick start](#quick-start) · [How it works](#how-it-works) · [Playground](https://ll333111.github.io/pr-truce/) · [Commands](#commands) · [Configuration](#configuration) · [中文](./README.zh-CN.md)
|
|
16
|
+
|
|
17
|
+
<br>
|
|
18
|
+
|
|
19
|
+
<picture>
|
|
20
|
+
<source media="(prefers-color-scheme: dark)" srcset="./assets/hero-dark.svg">
|
|
21
|
+
<img alt="Before: 23 AI and human review comments in one list. After: one pr-truce comment with 2 must-fix items and the rest folded away." src="./assets/hero-light.svg" width="880">
|
|
22
|
+
</picture>
|
|
23
|
+
|
|
24
|
+
</div>
|
|
25
|
+
|
|
26
|
+
## Why
|
|
27
|
+
|
|
28
|
+
AI reviewers comment on every push, and each one speaks its own dialect. CodeRabbit says *Major*, Gemini says *medium*, Copilot says nothing at all. A race condition lands in the same list as a rename suggestion, nobody can tell what actually blocks the merge, and every push buys the PR another round.
|
|
29
|
+
|
|
30
|
+
pr-truce turns all of it into **one sticky comment** that answers a single question: *what must change before this merges?*
|
|
31
|
+
|
|
32
|
+
- **Must fix**: human `blocking:` comments, `CHANGES_REQUESTED` reviews, and AI findings the bot itself rated Critical, Major or high.
|
|
33
|
+
- **Folded**: nits, AI Minor/Trivial/low/medium findings, and unrated AI suggestions, one click away and never in the way.
|
|
34
|
+
- **`/defer`**: one reply turns any thread into a linked follow-up issue and clears it from the merge gate.
|
|
35
|
+
- **Next**: who owns the next move (author, which reviewer, or *Ready to merge*), always up to date.
|
|
36
|
+
|
|
37
|
+
## Tested on real reviews
|
|
38
|
+
|
|
39
|
+
| What we ran | Result |
|
|
40
|
+
| :--- | :--- |
|
|
41
|
+
| **1,107 real AI review comments** from 89 public repositories | **74% folded** out of the Must-fix list, **0** left for manual triage |
|
|
42
|
+
| 400 CodeRabbit comments | Severity matched CodeRabbit's own rating on **400 / 400** |
|
|
43
|
+
| 400 Gemini Code Assist comments | Severity matched Gemini's own rating on **400 / 400** |
|
|
44
|
+
| A real team's PR history, replayed through the engine | **20 / 20** approved, merged PRs reported *Ready to merge* |
|
|
45
|
+
|
|
46
|
+
It started with a pull request that went **18 review rounds, 34 commits and 70 files** before it was closed and restarted. Every review was careful; there was simply no shared list of what blocked the merge. pr-truce is that list.
|
|
47
|
+
|
|
48
|
+
## Quick start
|
|
49
|
+
|
|
50
|
+
Add `.github/workflows/pr-truce.yml`:
|
|
51
|
+
|
|
52
|
+
```yaml
|
|
53
|
+
name: PR Truce
|
|
54
|
+
|
|
55
|
+
on:
|
|
56
|
+
pull_request:
|
|
57
|
+
types: [opened, reopened, synchronize, ready_for_review, converted_to_draft]
|
|
58
|
+
pull_request_review:
|
|
59
|
+
types: [submitted, edited, dismissed]
|
|
60
|
+
pull_request_review_comment:
|
|
61
|
+
types: [created, edited]
|
|
62
|
+
issue_comment:
|
|
63
|
+
types: [created]
|
|
64
|
+
|
|
65
|
+
permissions:
|
|
66
|
+
contents: read
|
|
67
|
+
pull-requests: write
|
|
68
|
+
# issues: write # enable /defer follow-up issues
|
|
69
|
+
# checks: write # enable the PR Truce Gate merge check (mode: gate)
|
|
70
|
+
|
|
71
|
+
concurrency:
|
|
72
|
+
group: pr-truce-${{ github.event.pull_request.number || github.event.issue.number }}
|
|
73
|
+
cancel-in-progress: false
|
|
74
|
+
|
|
75
|
+
jobs:
|
|
76
|
+
truce:
|
|
77
|
+
if: github.event_name != 'issue_comment' || github.event.issue.pull_request != null
|
|
78
|
+
runs-on: ubuntu-latest
|
|
79
|
+
steps:
|
|
80
|
+
- uses: actions/checkout@v4
|
|
81
|
+
- uses: LL333111/pr-truce@v0.3.0
|
|
82
|
+
with:
|
|
83
|
+
github-token: ${{ secrets.GITHUB_TOKEN }}
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
Push it, then comment `/truce` on any open PR. Your first summary appears in seconds.
|
|
87
|
+
|
|
88
|
+
Prefer a generator? `npx pr-truce init` writes the workflow and a commented `.github/pr-truce.yml` for you (`--defer` and `--mode gate` turn on the extras).
|
|
89
|
+
|
|
90
|
+
**Turn on the merge gate** when you're ready: set `mode: gate` in `.github/pr-truce.yml`, uncomment `checks: write`, and require **`PR Truce Gate`** in your branch protection rules. It passes as soon as the Must-fix list is empty, even with nits still open.
|
|
91
|
+
|
|
92
|
+
## How it works
|
|
93
|
+
|
|
94
|
+
Every PR event re-evaluates the whole review timeline and updates one comment. No server, no database, no state to drift.
|
|
95
|
+
|
|
96
|
+
**It reads each AI reviewer in its own language.** CodeRabbit's Critical/Major/Minor/Trivial headers, Gemini's high/medium/low badges, `[P0]`–`[P3]` tags, and Conventional Comments prefixes (`blocking:`, `nit:`, `suggestion:` …) all map onto one scale. Known reviewers out of the box: CodeRabbit, Gemini Code Assist, Copilot, Cursor Bugbot, Codex, Claude, Greptile and Qodo.
|
|
97
|
+
|
|
98
|
+
**It keeps humans in charge.** A human `blocking:` comment or a request for changes always lands in Must fix. Unlabeled human questions go to *Needs confirmation*, so a real concern is never quietly dropped. Any thread can be moved with `/blocking` or `/non-blocking`.
|
|
99
|
+
|
|
100
|
+
**It fits how your team already works.**
|
|
101
|
+
- **Solo repos with an AI reviewer:** the AI reviews are the review. You own every next step, and the comment says *Ready to merge* the moment nothing blocks.
|
|
102
|
+
- **Approve instead of resolve:** when a reviewer approves after their last comment, their threads count as settled. No more clicking *Resolve* on fifteen conversations.
|
|
103
|
+
- **One approval or two:** one approval means ready by default; other requested reviewers show as optional. Set `required_approvals: 2` to wait for both.
|
|
104
|
+
- **The right re-reviewer:** after a push, the handoff names whoever actually asked for the changes.
|
|
105
|
+
|
|
106
|
+
**It keeps late AI noise out.** After round 2, new non-critical AI comments are folded automatically, so a fresh push doesn't reopen the review.
|
|
107
|
+
|
|
108
|
+
<details>
|
|
109
|
+
<summary><b>See a full sticky comment</b></summary>
|
|
110
|
+
|
|
111
|
+
```markdown
|
|
112
|
+
### PR Truce · Round 1/3 · 1 blocking left
|
|
113
|
+
|
|
114
|
+
**Next:** Waiting on author (`@alice`) — _1 must-fix item(s) waiting on author; then `@bob` re-reviews_
|
|
115
|
+
|
|
116
|
+
#### Must fix (1)
|
|
117
|
+
- [ ] `blocking` Split retry worker to async queue — `src/webhooks/retry.ts:48`
|
|
118
|
+
|
|
119
|
+
<details><summary>AI suggestions — medium / unrated (1)</summary>
|
|
120
|
+
|
|
121
|
+
- `copilot-pull-request-reviewer` _(unrated)_ Consider extracting the backoff loop into a helper — `src/webhooks/retry.ts:71`
|
|
122
|
+
|
|
123
|
+
</details>
|
|
124
|
+
|
|
125
|
+
<details><summary>Non-blocking / nits (2)</summary>
|
|
126
|
+
|
|
127
|
+
- `nit` Rename `cfg` to `retryConfig` — `src/webhooks/retry.ts:12`
|
|
128
|
+
- `suggestion` Extract delay math into helper — `src/webhooks/retry.ts:63`
|
|
129
|
+
|
|
130
|
+
</details>
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
Try every state in the [interactive playground](https://ll333111.github.io/pr-truce/), which runs the real engine in your browser.
|
|
134
|
+
|
|
135
|
+
</details>
|
|
136
|
+
|
|
137
|
+
## Commands
|
|
138
|
+
|
|
139
|
+
| Command | Where | What it does |
|
|
140
|
+
| :--- | :--- | :--- |
|
|
141
|
+
| `/defer [title]` | Thread reply | Opens a linked follow-up issue and clears the thread from the gate |
|
|
142
|
+
| `/blocking` | Thread reply | Moves the thread into Must fix |
|
|
143
|
+
| `/non-blocking` | Thread reply | Moves the thread out of Must fix |
|
|
144
|
+
| `/truce` | PR comment | Refreshes the summary now |
|
|
145
|
+
| `/sync-resolved [note]` | PR comment | Records a sync decision and clears the optional round limit |
|
|
146
|
+
|
|
147
|
+
## Audit any repo in 30 seconds
|
|
148
|
+
|
|
149
|
+
See how your team's reviews really go, read-only, nothing to install:
|
|
150
|
+
|
|
151
|
+
```bash
|
|
152
|
+
npx pr-truce audit owner/repo --limit 50
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
```text
|
|
156
|
+
pr-truce audit org/service · 50 PRs · threshold >3 rounds
|
|
157
|
+
────────────────────────────────────────────────────────────────────────
|
|
158
|
+
|
|
159
|
+
Summary
|
|
160
|
+
Avg rounds / PR : 2.1 (P50: 2 · P90: 5 · Max: 18)
|
|
161
|
+
Ping-pong PRs : 10/50 (20%) exceeded 3 rounds
|
|
162
|
+
Avg PR lifetime : 1.4 days (168 review threads)
|
|
163
|
+
|
|
164
|
+
Root-Cause Breakdown
|
|
165
|
+
Opened after Round 1 █████████░░░░░░░░░░░ 44.0%
|
|
166
|
+
Non-blocking / nits ███░░░░░░░░░░░░░░░░░ 14.9%
|
|
167
|
+
4+ reply threads █░░░░░░░░░░░░░░░░░░░ 3.0%
|
|
168
|
+
AI bot threads ░░░░░░░░░░░░░░░░░░░░ 0.0%
|
|
169
|
+
|
|
170
|
+
Longest Review Loops (Top 3)
|
|
171
|
+
#105 18 rounds 1.8d 65 comments feat(billing): batch retry worker for webh...
|
|
172
|
+
#86 6 rounds 1.2d 24 comments fix(export): stream large CSV downloads...
|
|
173
|
+
#83 6 rounds 1.5d 24 comments refactor(auth): unify tenant token checks...
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
Look at a time window with `--since 30d` (or a date like `2026-11-01`). Export it as Markdown (`--format markdown`) or a shareable SVG card (`--format svg --out audit.svg`), or try `npx pr-truce demo` offline.
|
|
177
|
+
|
|
178
|
+
Then turn your team's recurring feedback into a rules file your AI tools follow:
|
|
179
|
+
|
|
180
|
+
```bash
|
|
181
|
+
npx pr-truce distill owner/repo --out REVIEW.md
|
|
182
|
+
npx pr-truce distill owner/repo --target claude-md --out CLAUDE.md
|
|
183
|
+
npx pr-truce distill owner/repo --target cursor-rules --out .cursor/rules/pr-truce.mdc
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
## Why pr-truce
|
|
187
|
+
|
|
188
|
+
| | pr-truce | GitHub "require conversation resolution" | Danger JS | Hosted review platforms |
|
|
189
|
+
| :--- | :---: | :---: | :---: | :---: |
|
|
190
|
+
| Reads each AI reviewer's own severity | ✅ | — | write it yourself | — |
|
|
191
|
+
| Gates only on what actually blocks | ✅ | every thread blocks | write it yourself | varies |
|
|
192
|
+
| `/defer` to a follow-up issue | ✅ | — | — | varies |
|
|
193
|
+
| Says who owns the next step | ✅ | — | — | ✅ |
|
|
194
|
+
| Runs in your own Actions runner, free | ✅ | ✅ | ✅ | — |
|
|
195
|
+
|
|
196
|
+
## Private by design
|
|
197
|
+
|
|
198
|
+
- Runs entirely inside your GitHub Actions runner. Code and comments never leave GitHub.
|
|
199
|
+
- No backend, no telemetry, no LLM API key.
|
|
200
|
+
- Starts with two permissions (`contents: read`, `pull-requests: write`); add `issues: write` and `checks: write` only for the features you turn on.
|
|
201
|
+
- Reads its config from the base branch, so a pull request can't loosen its own rules, and a typo in the config fails loudly instead of being silently ignored.
|
|
202
|
+
|
|
203
|
+
## Configuration
|
|
204
|
+
|
|
205
|
+
Everything is optional; the defaults work out of the box. Put overrides in `.github/pr-truce.yml`.
|
|
206
|
+
|
|
207
|
+
<details>
|
|
208
|
+
<summary>All options with defaults</summary>
|
|
209
|
+
|
|
210
|
+
```yaml
|
|
211
|
+
mode: summary # summary | gate
|
|
212
|
+
max_rounds: 3
|
|
213
|
+
max_thread_replies: 4
|
|
214
|
+
lock_contract_round: 1
|
|
215
|
+
required_approvals: 1 # approvals before "Ready to merge"
|
|
216
|
+
|
|
217
|
+
classification:
|
|
218
|
+
unlabeled_mode: triage # triage | review_state | blocking | non_blocking
|
|
219
|
+
blocking_prefixes: [blocking, blocker, issue, bug, security, important, critical, must, p0, p1]
|
|
220
|
+
non_blocking_prefixes: [nit, nitpick, suggestion, thought, praise, question, chore, optional, fyi, minor, p2, p3]
|
|
221
|
+
|
|
222
|
+
ai_bot_policy:
|
|
223
|
+
enabled: true
|
|
224
|
+
downgrade_nits: true
|
|
225
|
+
max_rounds: 2 # fold new non-critical AI comments after this round
|
|
226
|
+
unrated: collapse # AI comments with no rating: collapse | needs_triage
|
|
227
|
+
medium: collapse # AI comments rated medium: collapse | needs_triage
|
|
228
|
+
|
|
229
|
+
defer:
|
|
230
|
+
enabled: true
|
|
231
|
+
allowed_authors: reviewer_or_maintainer
|
|
232
|
+
issue_labels: ["pr-truce:deferred", "follow-up"]
|
|
233
|
+
resolve_thread: true
|
|
234
|
+
|
|
235
|
+
circuit_breaker:
|
|
236
|
+
enabled: false # flag PRs past max_rounds
|
|
237
|
+
label: "needs-sync"
|
|
238
|
+
escalate_to: []
|
|
239
|
+
|
|
240
|
+
gate:
|
|
241
|
+
check_name: "PR Truce Gate"
|
|
242
|
+
fail_on_circuit_breaker: false
|
|
243
|
+
fail_on_needs_triage: false
|
|
244
|
+
|
|
245
|
+
dashboard:
|
|
246
|
+
show_footer: true
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
</details>
|
|
250
|
+
|
|
251
|
+
<details>
|
|
252
|
+
<summary>Action inputs and outputs</summary>
|
|
253
|
+
|
|
254
|
+
**Inputs:** `github-token` (required), `mode`, `max-rounds`, `bot-login` (set it to your app's bot login, e.g. `my-app[bot]`, when you run with a GitHub App token).
|
|
255
|
+
|
|
256
|
+
**Outputs:** `round`, `blocking-count`, `needs-triage-count`, `non-blocking-count`, `ai-suggestion-count`, `gate-passed`, `waiting-on`, `circuit-breaker-tripped`, `data-complete`.
|
|
257
|
+
|
|
258
|
+
</details>
|
|
259
|
+
|
|
260
|
+
## Contributing
|
|
261
|
+
|
|
262
|
+
Issues and pull requests are welcome, and the [good first issues](https://github.com/LL333111/pr-truce/labels/good%20first%20issue) are a great place to start.
|
|
263
|
+
|
|
264
|
+
```bash
|
|
265
|
+
npm install
|
|
266
|
+
npm run check # typecheck, tests, bundles
|
|
267
|
+
npm run demo # offline audit, dashboard and distill preview
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
See [CONTRIBUTING.md](./CONTRIBUTING.md). MIT licensed.
|
package/README.zh-CN.md
ADDED
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
3
|
+
# pr-truce
|
|
4
|
+
|
|
5
|
+
**把所有 AI 和人工 code review,合成一张 Must fix 清单。**
|
|
6
|
+
|
|
7
|
+
CodeRabbit、Gemini、Copilot 和你的同事照常 review。<br>
|
|
8
|
+
pr-truce 读懂每一位 reviewer 真正标了什么,把噪音折叠起来,告诉所有人到底什么挡着合并。
|
|
9
|
+
|
|
10
|
+
[](https://github.com/LL333111/pr-truce/actions/workflows/ci.yml)
|
|
11
|
+
[](https://github.com/LL333111/pr-truce/releases)
|
|
12
|
+
[](#快速开始)
|
|
13
|
+
[](./LICENSE)
|
|
14
|
+
|
|
15
|
+
[快速开始](#快速开始) · [工作原理](#工作原理) · [在线模拟器](https://ll333111.github.io/pr-truce/) · [评论指令](#评论指令) · [配置项](#配置项) · [English](./README.md)
|
|
16
|
+
|
|
17
|
+
<br>
|
|
18
|
+
|
|
19
|
+
<picture>
|
|
20
|
+
<source media="(prefers-color-scheme: dark)" srcset="./assets/hero-dark.svg">
|
|
21
|
+
<img alt="之前:23 条 AI 和人工 review 评论混在一起。之后:一条 pr-truce 评论,2 条必改,其余全部折叠。" src="./assets/hero-light.svg" width="880">
|
|
22
|
+
</picture>
|
|
23
|
+
|
|
24
|
+
</div>
|
|
25
|
+
|
|
26
|
+
## 为什么需要它
|
|
27
|
+
|
|
28
|
+
AI reviewer 每次 push 都会评论一遍,而且各说各的话:CodeRabbit 说 *Major*,Gemini 说 *medium*,Copilot 干脆不标。一个竞态 bug 和一条改名建议躺在同一个列表里,没人能一眼看出到底什么挡着合并,每 push 一次,PR 就又多一轮。
|
|
29
|
+
|
|
30
|
+
pr-truce 把这一切收拢成**一条置顶评论**,只回答一个问题:*合并前到底必须改什么?*
|
|
31
|
+
|
|
32
|
+
- **Must fix**:人工的 `blocking:` 评论、`CHANGES_REQUESTED` review,以及 bot 自己标为 Critical、Major 或 high 的 AI 发现。
|
|
33
|
+
- **折叠**:nit、AI 标的 Minor/Trivial/low/medium,以及没有评级的 AI 建议,点一下就能看,但绝不挡路。
|
|
34
|
+
- **`/defer`**:回复一句就把任意线程转成关联的后续 issue,并移出合并门禁。
|
|
35
|
+
- **Next**:下一步该谁动(作者、哪位 reviewer,还是 *Ready to merge*),始终是最新的。
|
|
36
|
+
|
|
37
|
+
## 用真实 review 验证过
|
|
38
|
+
|
|
39
|
+
| 测试内容 | 结果 |
|
|
40
|
+
| :--- | :--- |
|
|
41
|
+
| 89 个公开仓库的 **1,107 条真实 AI review 评论** | **74% 被折叠**出 Must fix 清单,需要人工逐条确认的:**0** |
|
|
42
|
+
| 400 条 CodeRabbit 评论 | 严重级别与 CodeRabbit 自己标的 **400 / 400** 一致 |
|
|
43
|
+
| 400 条 Gemini Code Assist 评论 | 严重级别与 Gemini 自己标的 **400 / 400** 一致 |
|
|
44
|
+
| 一个真实团队的 PR 历史,完整回放 | **20 / 20** 个已批准并合并的 PR 都显示 *Ready to merge* |
|
|
45
|
+
|
|
46
|
+
它源自一个走了 **18 轮 review、34 个 commit、70 个文件**最后关掉重来的 PR。每一轮 review 都很认真,只是没有一张大家都认的"挡合并"清单。pr-truce 就是这张清单。
|
|
47
|
+
|
|
48
|
+
## 快速开始
|
|
49
|
+
|
|
50
|
+
新建 `.github/workflows/pr-truce.yml`:
|
|
51
|
+
|
|
52
|
+
```yaml
|
|
53
|
+
name: PR Truce
|
|
54
|
+
|
|
55
|
+
on:
|
|
56
|
+
pull_request:
|
|
57
|
+
types: [opened, reopened, synchronize, ready_for_review, converted_to_draft]
|
|
58
|
+
pull_request_review:
|
|
59
|
+
types: [submitted, edited, dismissed]
|
|
60
|
+
pull_request_review_comment:
|
|
61
|
+
types: [created, edited]
|
|
62
|
+
issue_comment:
|
|
63
|
+
types: [created]
|
|
64
|
+
|
|
65
|
+
permissions:
|
|
66
|
+
contents: read
|
|
67
|
+
pull-requests: write
|
|
68
|
+
# issues: write # 启用 /defer 建后续 issue
|
|
69
|
+
# checks: write # 启用 PR Truce Gate 合并检查(mode: gate)
|
|
70
|
+
|
|
71
|
+
concurrency:
|
|
72
|
+
group: pr-truce-${{ github.event.pull_request.number || github.event.issue.number }}
|
|
73
|
+
cancel-in-progress: false
|
|
74
|
+
|
|
75
|
+
jobs:
|
|
76
|
+
truce:
|
|
77
|
+
if: github.event_name != 'issue_comment' || github.event.issue.pull_request != null
|
|
78
|
+
runs-on: ubuntu-latest
|
|
79
|
+
steps:
|
|
80
|
+
- uses: actions/checkout@v4
|
|
81
|
+
- uses: LL333111/pr-truce@v0.3.0
|
|
82
|
+
with:
|
|
83
|
+
github-token: ${{ secrets.GITHUB_TOKEN }}
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
推上去,在任意打开的 PR 下评论 `/truce`,几秒后就能看到第一份摘要。
|
|
87
|
+
|
|
88
|
+
想一键生成?`npx pr-truce init` 会帮你写好 workflow 和带注释的 `.github/pr-truce.yml`(加 `--defer`、`--mode gate` 开启进阶功能)。
|
|
89
|
+
|
|
90
|
+
**准备好了就打开合并门禁**:在 `.github/pr-truce.yml` 设 `mode: gate`,取消 `checks: write` 的注释,并在分支保护规则里勾选 **`PR Truce Gate`**。Must fix 清单一清空它就通过,nit 没处理也不影响。
|
|
91
|
+
|
|
92
|
+
## 工作原理
|
|
93
|
+
|
|
94
|
+
每个 PR 事件都会重新计算完整的 review 时间线,只更新一条评论。没有服务器,没有数据库,没有会漂移的状态。
|
|
95
|
+
|
|
96
|
+
**用每个 AI reviewer 自己的语言读它。** CodeRabbit 的 Critical/Major/Minor/Trivial、Gemini 的 high/medium/low 徽章、`[P0]`–`[P3]` 标签,以及 Conventional Comments 前缀(`blocking:`、`nit:`、`suggestion:` …)都映射到同一套级别。开箱即认:CodeRabbit、Gemini Code Assist、Copilot、Cursor Bugbot、Codex、Claude、Greptile、Qodo。
|
|
97
|
+
|
|
98
|
+
**人说了算。** 人工的 `blocking:` 评论或 Request changes 一定进 Must fix;没有标注的人工提问进 *Needs confirmation*,真正的顾虑绝不会被悄悄丢掉。任何线程都能用 `/blocking` 或 `/non-blocking` 改判。
|
|
99
|
+
|
|
100
|
+
**贴合团队现有的习惯。**
|
|
101
|
+
- **一个人的仓库 + AI reviewer**:AI 的 review 就是 review,下一步永远是你自己,没有挡合并的问题就立刻显示 *Ready to merge*。
|
|
102
|
+
- **用批准代替 resolve**:reviewer 在自己最后一条评论之后批准,他开的线程就算解决了,不用再一个个点 *Resolve*。
|
|
103
|
+
- **一个批准还是两个**:默认一个批准即可合并,其他被请求的人显示为可选;设 `required_approvals: 2` 就等齐两人。
|
|
104
|
+
- **找对复审人**:push 之后,交接对象就是真正提出修改的那个人。
|
|
105
|
+
|
|
106
|
+
**挡住后来的 AI 噪音。** 第 2 轮之后,AI 新提的非致命评论自动折叠,新的 push 不会把 review 重新打开。
|
|
107
|
+
|
|
108
|
+
<details>
|
|
109
|
+
<summary><b>看一条完整的置顶评论</b></summary>
|
|
110
|
+
|
|
111
|
+
```markdown
|
|
112
|
+
### PR Truce · Round 1/3 · 1 blocking left
|
|
113
|
+
|
|
114
|
+
**Next:** Waiting on author (`@alice`) — _1 must-fix item(s) waiting on author; then `@bob` re-reviews_
|
|
115
|
+
|
|
116
|
+
#### Must fix (1)
|
|
117
|
+
- [ ] `blocking` Split retry worker to async queue — `src/webhooks/retry.ts:48`
|
|
118
|
+
|
|
119
|
+
<details><summary>AI suggestions — medium / unrated (1)</summary>
|
|
120
|
+
|
|
121
|
+
- `copilot-pull-request-reviewer` _(unrated)_ Consider extracting the backoff loop into a helper — `src/webhooks/retry.ts:71`
|
|
122
|
+
|
|
123
|
+
</details>
|
|
124
|
+
|
|
125
|
+
<details><summary>Non-blocking / nits (2)</summary>
|
|
126
|
+
|
|
127
|
+
- `nit` Rename `cfg` to `retryConfig` — `src/webhooks/retry.ts:12`
|
|
128
|
+
- `suggestion` Extract delay math into helper — `src/webhooks/retry.ts:63`
|
|
129
|
+
|
|
130
|
+
</details>
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
在[在线模拟器](https://ll333111.github.io/pr-truce/)里可以试遍所有状态,浏览器里跑的就是真实引擎。
|
|
134
|
+
|
|
135
|
+
</details>
|
|
136
|
+
|
|
137
|
+
## 评论指令
|
|
138
|
+
|
|
139
|
+
| 指令 | 位置 | 作用 |
|
|
140
|
+
| :--- | :--- | :--- |
|
|
141
|
+
| `/defer [标题]` | 线程回复 | 创建关联的后续 issue,并把线程移出门禁 |
|
|
142
|
+
| `/blocking` | 线程回复 | 移入 Must fix |
|
|
143
|
+
| `/non-blocking` | 线程回复 | 移出 Must fix |
|
|
144
|
+
| `/truce` | PR 评论 | 立即刷新摘要 |
|
|
145
|
+
| `/sync-resolved [结论]` | PR 评论 | 记录对齐结论,解除可选的轮次上限 |
|
|
146
|
+
|
|
147
|
+
## 30 秒诊断任意仓库
|
|
148
|
+
|
|
149
|
+
只读,不用安装,看看你们团队的 review 实际是什么样:
|
|
150
|
+
|
|
151
|
+
```bash
|
|
152
|
+
npx pr-truce audit owner/repo --limit 50
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
```text
|
|
156
|
+
pr-truce audit org/service · 50 PRs · threshold >3 rounds
|
|
157
|
+
────────────────────────────────────────────────────────────────────────
|
|
158
|
+
|
|
159
|
+
Summary
|
|
160
|
+
Avg rounds / PR : 2.1 (P50: 2 · P90: 5 · Max: 18)
|
|
161
|
+
Ping-pong PRs : 10/50 (20%) exceeded 3 rounds
|
|
162
|
+
Avg PR lifetime : 1.4 days (168 review threads)
|
|
163
|
+
|
|
164
|
+
Root-Cause Breakdown
|
|
165
|
+
Opened after Round 1 █████████░░░░░░░░░░░ 44.0%
|
|
166
|
+
Non-blocking / nits ███░░░░░░░░░░░░░░░░░ 14.9%
|
|
167
|
+
4+ reply threads █░░░░░░░░░░░░░░░░░░░ 3.0%
|
|
168
|
+
AI bot threads ░░░░░░░░░░░░░░░░░░░░ 0.0%
|
|
169
|
+
|
|
170
|
+
Longest Review Loops (Top 3)
|
|
171
|
+
#105 18 rounds 1.8d 65 comments feat(billing): batch retry worker for webh...
|
|
172
|
+
#86 6 rounds 1.2d 24 comments fix(export): stream large CSV downloads...
|
|
173
|
+
#83 6 rounds 1.5d 24 comments refactor(auth): unify tenant token checks...
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
用 `--since 30d`(或 `2026-11-01` 这样的日期)只看某段时间。可导出 Markdown(`--format markdown`)或可分享的 SVG 卡片(`--format svg --out audit.svg`),也可以离线跑 `npx pr-truce demo`。
|
|
177
|
+
|
|
178
|
+
再把团队反复提的意见提炼成 AI 工具会遵守的规则文件:
|
|
179
|
+
|
|
180
|
+
```bash
|
|
181
|
+
npx pr-truce distill owner/repo --out REVIEW.md
|
|
182
|
+
npx pr-truce distill owner/repo --target claude-md --out CLAUDE.md
|
|
183
|
+
npx pr-truce distill owner/repo --target cursor-rules --out .cursor/rules/pr-truce.mdc
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
## 为什么选 pr-truce
|
|
187
|
+
|
|
188
|
+
| | pr-truce | GitHub "require conversation resolution" | Danger JS | 托管式 review 平台 |
|
|
189
|
+
| :--- | :---: | :---: | :---: | :---: |
|
|
190
|
+
| 读懂每个 AI reviewer 自己标的级别 | ✅ | — | 需要自己写 | — |
|
|
191
|
+
| 只挡真正挡合并的问题 | ✅ | 每条线程都挡 | 需要自己写 | 视平台而定 |
|
|
192
|
+
| `/defer` 转后续 issue | ✅ | — | — | 视平台而定 |
|
|
193
|
+
| 告诉你下一步该谁动 | ✅ | — | — | ✅ |
|
|
194
|
+
| 跑在你自己的 Actions runner 上,免费 | ✅ | ✅ | ✅ | — |
|
|
195
|
+
|
|
196
|
+
## 隐私优先
|
|
197
|
+
|
|
198
|
+
- 完全运行在你自己的 GitHub Actions runner 里,代码和评论不出 GitHub。
|
|
199
|
+
- 无后端、无遥测、不需要 LLM API key。
|
|
200
|
+
- 起步只要两个权限(`contents: read`、`pull-requests: write`),用到哪个功能再加 `issues: write` 或 `checks: write`。
|
|
201
|
+
- 配置从 base 分支读取,PR 改不了自己的规则;配置写错会直接报错,而不是悄悄失效。
|
|
202
|
+
|
|
203
|
+
## 配置项
|
|
204
|
+
|
|
205
|
+
全部可选,默认值开箱即用。需要覆盖时写在 `.github/pr-truce.yml`。
|
|
206
|
+
|
|
207
|
+
<details>
|
|
208
|
+
<summary>全部选项及默认值</summary>
|
|
209
|
+
|
|
210
|
+
```yaml
|
|
211
|
+
mode: summary # summary | gate
|
|
212
|
+
max_rounds: 3
|
|
213
|
+
max_thread_replies: 4
|
|
214
|
+
lock_contract_round: 1
|
|
215
|
+
required_approvals: 1 # 显示 "Ready to merge" 需要的批准数
|
|
216
|
+
|
|
217
|
+
classification:
|
|
218
|
+
unlabeled_mode: triage # triage | review_state | blocking | non_blocking
|
|
219
|
+
blocking_prefixes: [blocking, blocker, issue, bug, security, important, critical, must, p0, p1]
|
|
220
|
+
non_blocking_prefixes: [nit, nitpick, suggestion, thought, praise, question, chore, optional, fyi, minor, p2, p3]
|
|
221
|
+
|
|
222
|
+
ai_bot_policy:
|
|
223
|
+
enabled: true
|
|
224
|
+
downgrade_nits: true
|
|
225
|
+
max_rounds: 2 # 这一轮之后,AI 新提的非致命评论自动折叠
|
|
226
|
+
unrated: collapse # 没有评级的 AI 评论:collapse | needs_triage
|
|
227
|
+
medium: collapse # 标为 medium 的 AI 评论:collapse | needs_triage
|
|
228
|
+
|
|
229
|
+
defer:
|
|
230
|
+
enabled: true
|
|
231
|
+
allowed_authors: reviewer_or_maintainer
|
|
232
|
+
issue_labels: ["pr-truce:deferred", "follow-up"]
|
|
233
|
+
resolve_thread: true
|
|
234
|
+
|
|
235
|
+
circuit_breaker:
|
|
236
|
+
enabled: false # 标出超过 max_rounds 的 PR
|
|
237
|
+
label: "needs-sync"
|
|
238
|
+
escalate_to: []
|
|
239
|
+
|
|
240
|
+
gate:
|
|
241
|
+
check_name: "PR Truce Gate"
|
|
242
|
+
fail_on_circuit_breaker: false
|
|
243
|
+
fail_on_needs_triage: false
|
|
244
|
+
|
|
245
|
+
dashboard:
|
|
246
|
+
show_footer: true
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
</details>
|
|
250
|
+
|
|
251
|
+
<details>
|
|
252
|
+
<summary>Action 输入与输出</summary>
|
|
253
|
+
|
|
254
|
+
**输入:** `github-token`(必填)、`mode`、`max-rounds`、`bot-login`(用 GitHub App token 运行时,设为该 App 的 bot 账号,如 `my-app[bot]`)。
|
|
255
|
+
|
|
256
|
+
**输出:** `round`、`blocking-count`、`needs-triage-count`、`non-blocking-count`、`ai-suggestion-count`、`gate-passed`、`waiting-on`、`circuit-breaker-tripped`、`data-complete`。
|
|
257
|
+
|
|
258
|
+
</details>
|
|
259
|
+
|
|
260
|
+
## 参与贡献
|
|
261
|
+
|
|
262
|
+
欢迎提 issue 和 PR,[good first issues](https://github.com/LL333111/pr-truce/labels/good%20first%20issue) 是不错的起点。
|
|
263
|
+
|
|
264
|
+
```bash
|
|
265
|
+
npm install
|
|
266
|
+
npm run check # 类型检查、测试、打包
|
|
267
|
+
npm run demo # 离线预览 audit、看板和 distill
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
详见 [CONTRIBUTING.md](./CONTRIBUTING.md)。MIT 协议。
|
package/action.yml
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
name: "PR Truce"
|
|
2
|
+
description: "One Must-fix list from AI and human PR reviews: reads bot severity, folds nits, /defer to issues."
|
|
3
|
+
author: "pr-truce contributors"
|
|
4
|
+
|
|
5
|
+
branding:
|
|
6
|
+
icon: "shield"
|
|
7
|
+
color: "green"
|
|
8
|
+
|
|
9
|
+
inputs:
|
|
10
|
+
github-token:
|
|
11
|
+
description: "GitHub token (summary mode: pull-requests:write; add issues:write for /defer and checks:write for gate mode)."
|
|
12
|
+
required: false
|
|
13
|
+
default: ${{ github.token }}
|
|
14
|
+
config-path:
|
|
15
|
+
description: "Path to the PR Truce YAML config file in the repository."
|
|
16
|
+
required: false
|
|
17
|
+
default: ".github/pr-truce.yml"
|
|
18
|
+
mode:
|
|
19
|
+
description: "Override action mode ('summary' to only update the sticky comment, or 'gate' to also emit Check Runs)."
|
|
20
|
+
required: false
|
|
21
|
+
max-rounds:
|
|
22
|
+
description: "Override max review rounds before tripping the circuit breaker."
|
|
23
|
+
required: false
|
|
24
|
+
bot-login:
|
|
25
|
+
description: "Login PR Truce posts as when github-token is a GitHub App token (e.g. 'my-app[bot]'). Needed so it recognizes its own /defer receipts; not needed for GITHUB_TOKEN or a PAT."
|
|
26
|
+
required: false
|
|
27
|
+
dry-run:
|
|
28
|
+
description: "If 'true', compute and log the convergence dashboard without mutating GitHub."
|
|
29
|
+
required: false
|
|
30
|
+
default: "false"
|
|
31
|
+
|
|
32
|
+
outputs:
|
|
33
|
+
round:
|
|
34
|
+
description: "Current review round number for the pull request."
|
|
35
|
+
blocking-count:
|
|
36
|
+
description: "Number of unresolved blocking review threads."
|
|
37
|
+
needs-triage-count:
|
|
38
|
+
description: "Number of unresolved unlabeled review threads awaiting confirmation."
|
|
39
|
+
non-blocking-count:
|
|
40
|
+
description: "Number of unresolved non-blocking / nit threads (not counting AI suggestions)."
|
|
41
|
+
ai-suggestion-count:
|
|
42
|
+
description: "Number of unresolved AI comments folded into the AI suggestions section (rated medium or unrated)."
|
|
43
|
+
circuit-breaker-tripped:
|
|
44
|
+
description: "Whether the review circuit breaker is currently tripped ('true' or 'false')."
|
|
45
|
+
gate-passed:
|
|
46
|
+
description: "Whether the PR Truce blocking-only merge gate passed ('true' or 'false')."
|
|
47
|
+
waiting-on:
|
|
48
|
+
description: "Who currently owns the next action ('author', 'reviewer', 'ready', or 'draft')."
|
|
49
|
+
data-complete:
|
|
50
|
+
description: "Whether the PR snapshot was fetched without API truncation ('true' or 'false')."
|
|
51
|
+
|
|
52
|
+
runs:
|
|
53
|
+
using: "node24"
|
|
54
|
+
main: "dist/action/index.js"
|