From 57b2c22a00057ed3c76f891dfb936bca484f51fb Mon Sep 17 00:00:00 2001 From: lezi-fun <177434121+lezi-fun@users.noreply.github.com> Date: Fri, 14 Aug 2026 12:09:35 +0800 Subject: [PATCH] fix: keep fork commit reviews API-only --- .github/workflows/review-reusable.yml | 2 +- README-zh.md | 2 +- README.md | 2 +- test/workflow-security.test.ts | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/review-reusable.yml b/.github/workflows/review-reusable.yml index cc547e5..e66ce05 100644 --- a/.github/workflows/review-reusable.yml +++ b/.github/workflows/review-reusable.yml @@ -207,7 +207,7 @@ jobs: ref: main path: ghbot-runtime - name: Check out current PR source for agent tasks - if: ${{ inputs.event_name == 'issue_comment' || (inputs.event_name == 'pull_request_target' && inputs.event_action != 'closed' && inputs.auto_resolve_conflicts == 'true') }} + if: ${{ inputs.event_name == 'issue_comment' || (inputs.event_name == 'pull_request_target' && inputs.event_action != 'closed' && inputs.auto_resolve_conflicts == 'true' && inputs.pull_head_repository == format('{0}/{1}', inputs.repository_owner, inputs.repository_name)) }} uses: actions/checkout@v4 with: repository: ${{ inputs.repository_owner }}/${{ inputs.repository_name }} diff --git a/README-zh.md b/README-zh.md index 683a84a..27cc66c 100644 --- a/README-zh.md +++ b/README-zh.md @@ -126,7 +126,7 @@ prompt 还会收到由宿主通过 GitHub 验证的请求者上下文:评论 具有 `write`、`maintain` 或 `admin` 权限的协作者也可以评论精确命令 `/conflict`,显式要求执行同一套受保护的冲突修复。即使 `AUTO_RESOLVE_CONFLICTS=false`,该命令也可以运行;它不要求先有一次通过的审核,因为修复提交 push 后一定会对新 head 重新完整审核,修复动作本身不会直接批准合并。 -仅处理当前 head 未变化且可写的 PR 分支。同仓库分支可直接写入;外部 fork 只有贡献者启用 **Allow edits from maintainers** 才可处理,并使用绑定已审核 head SHA 的 `--force-with-lease` 推送,因此贡献者新提交的 commit 不会被覆盖。旧 head、非冲突状态、关闭 maintainer edits 和未通过审核的 PR 都会跳过。ghbot 在宿主生成本地 merge,再把无 `.git`、无凭据的净化快照交给 goose。goose 可以修改直接冲突文件,也可以在兼容性确有需要时调整相关调用方、类型、测试、lockfile、配置或文档;受保护的 Agent 配置和凭证路径会被拒绝。 +自动冲突修复仅处理当前 head 未变化的同仓库 PR。外部 fork 的 `pull_request_target` 仍保持纯 GitHub API 审核,不 checkout 贡献者代码;贡献者启用 **Allow edits from maintainers** 后,maintainer 可以显式评论 `/conflict`,由可信的评论 workflow checkout PR head,并使用绑定已审核 head SHA 的 `--force-with-lease` 推送,因此贡献者新提交的 commit 不会被覆盖。旧 head、非冲突状态、关闭 maintainer edits 和未通过审核的 PR 都会跳过。ghbot 在宿主生成本地 merge,再把无 `.git`、无凭据的净化快照交给 goose。goose 可以修改直接冲突文件,也可以在兼容性确有需要时调整相关调用方、类型、测试、lockfile、配置或文档;受保护的 Agent 配置和凭证路径会被拒绝。 应用改动后,ghbot 检查未合并路径和 `git diff --check`。第二次隔离 goose 会审核完整 staged diff,并在配置后运行可信的 `CONFLICT_TEST_COMMAND`。只有第二次确认明确返回 `safeToCommit=true`,且远端 PR head 仍与审核 SHA 相同,才会创建普通 merge commit 并 push;绝不 force-push。新 commit 会触发 `synchronize` 并重新完整审核,不会把修复前的结论直接当作批准。 diff --git a/README.md b/README.md index be07f7c..cf0e161 100644 --- a/README.md +++ b/README.md @@ -112,7 +112,7 @@ Set `AUTO_RESOLVE_CONFLICTS=true` to allow goose to repair a PR that passed revi A collaborator with `write`, `maintain`, or `admin` permission can also explicitly request the same guarded repair by posting the exact command `/conflict`. This manual command works even when `AUTO_RESOLVE_CONFLICTS=false`; it does not require an earlier passing review because the resulting commit always triggers a new complete review before any merge decision. -Conflict repair applies to a current, writable PR head. Same-repository branches are writable directly; external forks are eligible only when the contributor enabled **Allow edits from maintainers**. Fork pushes use an explicit `--force-with-lease` tied to the reviewed head SHA, so a newly pushed contributor commit is never overwritten. Stale heads, non-dirty states, disabled maintainer edits, and failed reviews are skipped. ghbot creates the merge locally, gives goose a sanitized credential-free snapshot, and allows it to change direct conflict files plus related callers, types, tests, lockfiles, configuration, or documentation when necessary for compatibility. Protected agent/configuration and credential paths are rejected. +Automatic conflict repair applies to current same-repository PR heads. External fork commits remain API-only during `pull_request_target`; a maintainer can explicitly run `/conflict` when the contributor enabled **Allow edits from maintainers**. That trusted comment workflow checks out the PR head without persisted credentials and pushes with an explicit `--force-with-lease` tied to the reviewed head SHA, so a newly pushed contributor commit is never overwritten. Stale heads, non-dirty states, disabled maintainer edits, and failed reviews are skipped. ghbot creates the merge locally, gives goose a sanitized credential-free snapshot, and allows it to change direct conflict files plus related callers, types, tests, lockfiles, configuration, or documentation when necessary for compatibility. Protected agent/configuration and credential paths are rejected. After applying the proposed files, ghbot verifies there are no unmerged paths and runs `git diff --check`. A second isolated goose pass reviews the complete staged diff and, when configured, runs the trusted `CONFLICT_TEST_COMMAND`. The result is committed and pushed only when that final pass returns `safeToCommit=true` and the remote PR head still matches the reviewed SHA. ghbot never force-pushes. The new commit triggers a fresh `synchronize` review; the old decision is not reused as approval. diff --git a/test/workflow-security.test.ts b/test/workflow-security.test.ts index de2a757..9e3afe5 100644 --- a/test/workflow-security.test.ts +++ b/test/workflow-security.test.ts @@ -2,11 +2,11 @@ import assert from "node:assert/strict"; import fs from "node:fs/promises"; import test from "node:test"; -test("conflict repair checks out fork heads without persisting GitHub credentials", async () => { +test("pull_request_target checks out only same-repository heads without persisting credentials", async () => { const workflow = await fs.readFile(".github/workflows/review-reusable.yml", "utf8"); const caller = await fs.readFile(".github/workflows/review.yml", "utf8"); assert.match(workflow, /inputs\.auto_resolve_conflicts == 'true'/); - assert.doesNotMatch(workflow, /pull_head_repository == format\('\{0\}\/\{1\}'/); + assert.match(workflow, /pull_head_repository == format\('\{0\}\/\{1\}'/); assert.match(workflow, /fetch-depth:\s*0/); assert.doesNotMatch(workflow, /allow-unsafe-pr-checkout:\s*true/); assert.match(workflow, /GHBOT_GOOSE_BINARY:\s*\$\{\{ runner\.temp \}\}\/goose\/bin\/goose/);