fix: 自动安装 Webhook、修正 PR 审查范围与分支匹配语义

三个导致「提交了新 PR 但没有任何反应」的独立问题:

1. 从不创建 Webhook
   服务只被动接收事件,但配置仓库时不会去 Gitea 里建 Webhook,
   结果仓库永远收不到 push / PR 事件,看起来和坏掉一样。
   - 保存仓库时自动创建或更新 Webhook(POST /repos 返回值带 webhook 结果)
   - 新增 GET/POST /api/repos/:id/webhook 查询与修复
   - 仓库列表新增 Webhook 列,未配置可一键「修复 Webhook」
   - 新增 CR_WEBHOOK_URL,留空则推导为「Gitea 主机名 + 本服务端口」

2. 审查范围用了错的分支做基准
   resolveRange 优先取 managed_branch 而不是 job.base_ref,
   于是 PR 被拿去和一个无关分支比较;当两者内容相同就报
   「base and head resolve to the same commit」直接跳过。
   改为优先用该改动实际要合入的分支(PR 的目标分支),
   仅 push 事件回退到 managed_branch。

3. 检查分支的匹配语义反了
   原先要求 PR 的 head(功能分支)出现在 check_branches 里,
   而用户配置的是「要保护的目标分支」(如 prd/test),
   功能分支永远不会被列出,所以 PR 一律被过滤掉。
   新增 pullRequestMatches:PR 的 base 命中检查分支即审查,
   head 命中仍保留支持。这样「审查所有合入 prd/test 的改动」成立。

验证:PR offerpai/offerpai_h5#2 重跑通过,7 条内联评论、
2 条阻断、commit status failure、Issue #3 创建。
This commit is contained in:
2026-09-20 14:44:26 +08:00
parent 6dc77ce907
commit 34f2897888
6 changed files with 208 additions and 22 deletions
+5 -4
View File
@@ -38,7 +38,7 @@
<thead>
<tr>
<th>仓库</th><th>管理分支</th><th>检查分支</th><th>范围</th>
<th>启用</th><th>自动合并</th><th>阻断级别</th><th></th>
<th>Webhook</th><th>启用</th><th>自动合并</th><th>阻断级别</th><th></th>
</tr>
</thead>
<tbody></tbody>
@@ -80,7 +80,8 @@
<label>管理员 Token <input name="giteaToken" type="password" placeholder="留空表示不修改" /></label>
<label>Webhook 密钥 <input name="webhookSecret" type="password" placeholder="留空表示不修改" /></label>
<label>后台访问 Token <input name="adminToken" type="password" placeholder="留空表示不修改" /></label>
<p class="hint">Webhook 地址:<code id="hook-url"></code>(在仓库 Settings → Webhooks 中添加,密钥填上面这一项)</p>
<label>Webhook 回调地址 <input name="webhookUrl" placeholder="留空自动推导为 <Gitea 主机>:<本服务端口>" /></label>
<p class="hint">保存仓库时会自动在 Gitea 里创建/更新 Webhook,地址用上面这一项,密钥用 Webhook 密钥。<code id="hook-url"></code></p>
</fieldset>
<fieldset>
<legend>LLM(代码审查与历史摘要共用)</legend>
@@ -184,7 +185,7 @@
<button type="button" id="branch-create">克隆创建</button>
</span>
</label>
<p class="hint">所有检查通过后只合并到这一个分支。</p>
<p class="hint">所有检查通过后只合并到这一个分支;它也会出现在下面的检查分支里。</p>
<label>检查分支(可多选)
<span class="inline">
<input name="check_branches" placeholder="main,release/1.0" />
@@ -192,7 +193,7 @@
</span>
</label>
<div id="branch-list" class="branch-list"></div>
<p class="hint">这些分支都会被监控审查;只有指向管理分支的 PR 才会自动合并。</p>
<p class="hint">填「被保护的目标分支」。任何合并进这些分支的 PR 都会审查(功能分支不用列出来);向这些分支推送也会审查。只有指向管理分支的 PR 才会自动合并。</p>
</fieldset>
<fieldset>