Add R2 persistence and manual conflict repair
This commit is contained in:
1 parent
2d50da41cd
commit
e8ee698fa4
19 files changed
+1258
-62
No files matched your search
+9
-1
@@ -20,11 +20,19 @@ REVIEW_STRICTNESS=normal
|
||||
REVIEW_INSTRUCTIONS=
|
||||
# Comma-separated PR base-branch globs. Empty means all base branches.
|
||||
REVIEW_BRANCHES=
|
||||
# Persist repository knowledge in GitHub Actions cache. Authorized @bot agents
|
||||
# Persist repository knowledge in the configured private cache. Authorized @bot agents
|
||||
# can improve it only when write is explicitly enabled.
|
||||
REPOSITORY_KNOWLEDGE_ENABLED=true
|
||||
REPOSITORY_KNOWLEDGE_WRITE=false
|
||||
|
||||
# Optional Cloudflare R2 persistent storage. Configure all credential values
|
||||
# together. R2_PREFIX is an optional safe object-key namespace.
|
||||
R2_ENDPOINT=https://ACCOUNT_ID.r2.cloudflarestorage.com
|
||||
R2_BUCKET_NAME=ghbot-cache
|
||||
R2_PREFIX=
|
||||
R2_ACCESS_KEY_ID=
|
||||
R2_SECRET_ACCESS_KEY=
|
||||
|
||||
TRIAGE_ENABLED=true
|
||||
TRIAGE_LABELS=bug,enhancement,documentation,question,maintenance
|
||||
TRIAGE_DUPLICATE_LABEL=duplicate
|
||||
|
||||
@@ -98,6 +98,18 @@ on:
|
||||
required: false
|
||||
type: string
|
||||
default: "false"
|
||||
r2_endpoint:
|
||||
required: false
|
||||
type: string
|
||||
default: ""
|
||||
r2_bucket_name:
|
||||
required: false
|
||||
type: string
|
||||
default: ""
|
||||
r2_prefix:
|
||||
required: false
|
||||
type: string
|
||||
default: ""
|
||||
triage_enabled:
|
||||
required: false
|
||||
type: string
|
||||
@@ -167,9 +179,12 @@ on:
|
||||
required: false
|
||||
GITHUB_APP_INSTALLATION_ID:
|
||||
required: false
|
||||
R2_ACCESS_KEY_ID:
|
||||
required: false
|
||||
R2_SECRET_ACCESS_KEY:
|
||||
required: false
|
||||
|
||||
permissions:
|
||||
actions: write
|
||||
contents: write
|
||||
pull-requests: write
|
||||
checks: write
|
||||
@@ -199,8 +214,6 @@ jobs:
|
||||
- uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: 24
|
||||
cache: npm
|
||||
cache-dependency-path: ghbot-runtime/package-lock.json
|
||||
- name: Install goose CLI
|
||||
env:
|
||||
GOOSE_VERSION: v1.46.0
|
||||
@@ -213,21 +226,6 @@ jobs:
|
||||
working-directory: ghbot-runtime
|
||||
- run: npm run build
|
||||
working-directory: ghbot-runtime
|
||||
- name: Restore repository knowledge
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: ghbot-runtime/.ghbot-knowledge/repository.md
|
||||
key: ghbot-knowledge-${{ github.repository_id }}-${{ github.run_id }}
|
||||
restore-keys: |
|
||||
ghbot-knowledge-${{ github.repository_id }}-
|
||||
- name: Restore previous PR review
|
||||
if: ${{ inputs.event_name == 'pull_request_target' && inputs.event_action != 'closed' }}
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: ghbot-runtime/.ghbot-cache/pr-${{ inputs.pull_number }}.json
|
||||
key: ghbot-review-${{ github.repository_id }}-pr-${{ inputs.pull_number }}-${{ github.run_id }}
|
||||
restore-keys: |
|
||||
ghbot-review-${{ github.repository_id }}-pr-${{ inputs.pull_number }}-
|
||||
- run: node dist/src/actions/runReview.js
|
||||
working-directory: ghbot-runtime
|
||||
env:
|
||||
@@ -245,6 +243,11 @@ jobs:
|
||||
REVIEW_BRANCHES: ${{ inputs.review_branches }}
|
||||
REPOSITORY_KNOWLEDGE_ENABLED: ${{ inputs.repository_knowledge_enabled }}
|
||||
REPOSITORY_KNOWLEDGE_WRITE: ${{ inputs.repository_knowledge_write }}
|
||||
R2_ENDPOINT: ${{ inputs.r2_endpoint }}
|
||||
R2_BUCKET_NAME: ${{ inputs.r2_bucket_name }}
|
||||
R2_PREFIX: ${{ inputs.r2_prefix }}
|
||||
R2_ACCESS_KEY_ID: ${{ secrets.R2_ACCESS_KEY_ID }}
|
||||
R2_SECRET_ACCESS_KEY: ${{ secrets.R2_SECRET_ACCESS_KEY }}
|
||||
TRIAGE_ENABLED: ${{ inputs.triage_enabled }}
|
||||
TRIAGE_LABELS: ${{ inputs.triage_labels }}
|
||||
TRIAGE_DUPLICATE_LABEL: ${{ inputs.triage_duplicate_label }}
|
||||
@@ -284,8 +287,6 @@ jobs:
|
||||
- uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: 24
|
||||
cache: npm
|
||||
cache-dependency-path: ghbot-runtime/package-lock.json
|
||||
- name: Install goose CLI
|
||||
env:
|
||||
GOOSE_VERSION: v1.46.0
|
||||
@@ -298,13 +299,6 @@ jobs:
|
||||
working-directory: ghbot-runtime
|
||||
- run: npm run build
|
||||
working-directory: ghbot-runtime
|
||||
- name: Restore repository knowledge
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: ghbot-runtime/.ghbot-knowledge/repository.md
|
||||
key: ghbot-knowledge-${{ github.repository_id }}-${{ github.run_id }}
|
||||
restore-keys: |
|
||||
ghbot-knowledge-${{ github.repository_id }}-
|
||||
- run: node dist/src/actions/runReview.js
|
||||
working-directory: ghbot-runtime
|
||||
env:
|
||||
@@ -322,6 +316,11 @@ jobs:
|
||||
REVIEW_BRANCHES: ${{ inputs.review_branches }}
|
||||
REPOSITORY_KNOWLEDGE_ENABLED: ${{ inputs.repository_knowledge_enabled }}
|
||||
REPOSITORY_KNOWLEDGE_WRITE: ${{ inputs.repository_knowledge_write }}
|
||||
R2_ENDPOINT: ${{ inputs.r2_endpoint }}
|
||||
R2_BUCKET_NAME: ${{ inputs.r2_bucket_name }}
|
||||
R2_PREFIX: ${{ inputs.r2_prefix }}
|
||||
R2_ACCESS_KEY_ID: ${{ secrets.R2_ACCESS_KEY_ID }}
|
||||
R2_SECRET_ACCESS_KEY: ${{ secrets.R2_SECRET_ACCESS_KEY }}
|
||||
TRIAGE_ENABLED: ${{ inputs.triage_enabled }}
|
||||
TRIAGE_LABELS: ${{ inputs.triage_labels }}
|
||||
TRIAGE_DUPLICATE_LABEL: ${{ inputs.triage_duplicate_label }}
|
||||
|
||||
@@ -23,7 +23,6 @@ on:
|
||||
- cron: "17 * * * *"
|
||||
|
||||
permissions:
|
||||
actions: write
|
||||
contents: write
|
||||
pull-requests: write
|
||||
checks: write
|
||||
@@ -44,6 +43,8 @@ jobs:
|
||||
GH_APP_ID: ${{ secrets.GH_APP_ID }}
|
||||
GH_APP_PRIVATE_KEY: ${{ secrets.GH_APP_PRIVATE_KEY }}
|
||||
GH_APP_INSTALLATION_ID: ${{ secrets.GH_APP_INSTALLATION_ID }}
|
||||
R2_ACCESS_KEY_ID: ${{ secrets.R2_ACCESS_KEY_ID }}
|
||||
R2_SECRET_ACCESS_KEY: ${{ secrets.R2_SECRET_ACCESS_KEY }}
|
||||
with:
|
||||
event_name: ${{ github.event_name }}
|
||||
event_action: ${{ github.event.action }}
|
||||
@@ -70,6 +71,9 @@ jobs:
|
||||
review_branches: ${{ vars.REVIEW_BRANCHES || '' }}
|
||||
repository_knowledge_enabled: ${{ vars.REPOSITORY_KNOWLEDGE_ENABLED || 'true' }}
|
||||
repository_knowledge_write: ${{ vars.REPOSITORY_KNOWLEDGE_WRITE || 'false' }}
|
||||
r2_endpoint: ${{ vars.R2_ENDPOINT || '' }}
|
||||
r2_bucket_name: ${{ vars.R2_BUCKET_NAME || '' }}
|
||||
r2_prefix: ${{ vars.R2_PREFIX || '' }}
|
||||
triage_enabled: ${{ vars.TRIAGE_ENABLED || 'true' }}
|
||||
triage_labels: ${{ vars.TRIAGE_LABELS || 'bug,enhancement,documentation,question,maintenance' }}
|
||||
triage_duplicate_label: ${{ vars.TRIAGE_DUPLICATE_LABEL || 'duplicate' }}
|
||||
@@ -91,6 +95,8 @@ jobs:
|
||||
GH_APP_ID: ${{ secrets.GH_APP_ID }}
|
||||
GH_APP_PRIVATE_KEY: ${{ secrets.GH_APP_PRIVATE_KEY }}
|
||||
GH_APP_INSTALLATION_ID: ${{ secrets.GH_APP_INSTALLATION_ID }}
|
||||
R2_ACCESS_KEY_ID: ${{ secrets.R2_ACCESS_KEY_ID }}
|
||||
R2_SECRET_ACCESS_KEY: ${{ secrets.R2_SECRET_ACCESS_KEY }}
|
||||
with:
|
||||
event_name: schedule
|
||||
event_action: schedule
|
||||
@@ -111,6 +117,9 @@ jobs:
|
||||
review_branches: ${{ vars.REVIEW_BRANCHES || '' }}
|
||||
repository_knowledge_enabled: ${{ vars.REPOSITORY_KNOWLEDGE_ENABLED || 'true' }}
|
||||
repository_knowledge_write: ${{ vars.REPOSITORY_KNOWLEDGE_WRITE || 'false' }}
|
||||
r2_endpoint: ${{ vars.R2_ENDPOINT || '' }}
|
||||
r2_bucket_name: ${{ vars.R2_BUCKET_NAME || '' }}
|
||||
r2_prefix: ${{ vars.R2_PREFIX || '' }}
|
||||
triage_enabled: ${{ vars.TRIAGE_ENABLED || 'true' }}
|
||||
triage_labels: ${{ vars.TRIAGE_LABELS || 'bug,enhancement,documentation,question,maintenance' }}
|
||||
triage_duplicate_label: ${{ vars.TRIAGE_DUPLICATE_LABEL || 'duplicate' }}
|
||||
|
||||
+28
-8
@@ -36,9 +36,9 @@ goose 的审核结果固定包含四个顶层字段:
|
||||
|
||||
普通自动审核使用 GitHub API 按 PR 编号读取 metadata、完整文件列表和 diff,不执行不可信 PR 代码。只有显式开启冲突修复时才 checkout PR head,而且执行和测试都在无 GitHub 凭据的一次性净化容器中完成。来自 fork 或没有仓库权限的外部贡献者仍会正常得到自动审核,但不会被自动推送冲突修复。
|
||||
|
||||
## 增量审核缓存
|
||||
## Cloudflare R2 增量审核缓存
|
||||
|
||||
每次成功审核会把以下信息保存到 GitHub Actions cache:
|
||||
配置 Cloudflare R2 后,每次成功审核会把以下信息保存到私有存储桶:
|
||||
|
||||
- 仓库和 PR 编号
|
||||
- 已审核的 head SHA 和时间
|
||||
@@ -46,16 +46,24 @@ goose 的审核结果固定包含四个顶层字段:
|
||||
|
||||
新 commit 触发 `synchronize` 后,workflow 会恢复该 PR 最新的缓存。goose 同时收到旧审核结果和当前完整 PR diff,重新验证所有旧问题、移除已经修复的问题,并检查新 commit 引入的回归。旧的合并结论不会在没有新审核的情况下直接复用。
|
||||
|
||||
PR 标题、描述或 base branch 变化触发 `edited` 时也会重新审核。关闭或合并 PR 不会主动删除 Actions cache;旧条目由 GitHub 的常规缓存保留策略自然清理。缓存不保存 API key、完整 diff 或 prompt。
|
||||
PR 标题、描述或 base branch 变化触发 `edited` 时也会重新审核。对象按仓库 ID 和 PR 编号隔离;`latest.json` 用于加速下一次审核,`reviews/<head-sha>.json` 留存每个成功审核过的 head。关闭或合并 PR 不会主动删除这些对象。缓存不保存 API key、完整 diff 或 prompt。
|
||||
|
||||
需要同时配置:
|
||||
|
||||
- Actions Secrets:`R2_ACCESS_KEY_ID`、`R2_SECRET_ACCESS_KEY`
|
||||
- Repository Variables:`R2_ENDPOINT`、`R2_BUCKET_NAME`
|
||||
- 可选 Variable:`R2_PREFIX`,例如 `forum-114614`
|
||||
|
||||
建议使用只允许读写这个存储桶对象的专用 R2 Token。ghbot 使用恢复内容前会校验格式以及仓库/PR 身份。R2 密钥只交给宿主进程,不会传入 goose 容器、PR 测试命令或 git 子进程。未配置 R2 或 R2 暂时故障时,审核仍会继续,只是不使用持久历史。
|
||||
|
||||
## 可自我改进的仓库认知缓存
|
||||
|
||||
ghbot 可以把一份简洁的仓库认知文件保存在 GitHub Actions cache 中。它按仓库 ID 隔离,与单个 PR 的审核缓存分开,因此 PR 关闭或合并时不会删除。自动审核可以参考其中长期有效的架构、支持环境、可信测试命令、代码约定和常见坑。
|
||||
ghbot 可以把一份简洁的仓库认知文件保存在同一个私有 R2 存储桶中。它按仓库 ID 隔离,与单个 PR 的审核缓存分开,因此 PR 关闭或合并时不会删除。自动审核可以参考其中长期有效的架构、支持环境、可信测试命令、代码约定和常见坑。
|
||||
|
||||
- `REPOSITORY_KNOWLEDGE_ENABLED`:恢复并使用仓库认知,默认 `true`。
|
||||
- `REPOSITORY_KNOWLEDGE_WRITE`:允许有权限的 `@bot` goose Agent 改进认知缓存,默认 `false`。
|
||||
|
||||
Agent 只能编辑临时快照中的 `.ghbot/repository-knowledge.md` 草稿。ghbot 会校验内容,拒绝凭证、私钥和超过 32 KiB 的内容,再把它复制到 reusable workflow runtime 的 `.ghbot-knowledge/repository.md`,由 `actions/cache` 用仓库级 key 持久化。它不会提交到业务仓库,Agent 仍然拿不到 GitHub 凭证。
|
||||
Agent 只能编辑临时快照中的 `.ghbot/repository-knowledge.md` 草稿。ghbot 会校验内容,拒绝凭证、私钥和超过 32 KiB 的内容,再把 runtime 副本持久化到按仓库隔离的 R2 对象。它不会提交到业务仓库,Agent 也拿不到 GitHub 或 R2 凭证。
|
||||
|
||||
## Issue 和 PR 分类
|
||||
|
||||
@@ -108,6 +116,8 @@ Agent 在一次性 Docker 容器中运行:
|
||||
|
||||
设置 `AUTO_RESOLVE_CONFLICTS=true` 后,如果 AI 审核已经通过,但 GitHub 报告 `mergeable=false` 且 `mergeable_state=dirty`,goose 可以自动解决冲突。它与 `AUTO_MERGE` 相互独立,因此可以只开启冲突修复而继续禁止自动合并。
|
||||
|
||||
具有 `write`、`maintain` 或 `admin` 权限的协作者也可以评论精确命令 `/conflict`,显式要求执行同一套受保护的冲突修复。即使 `AUTO_RESOLVE_CONFLICTS=false`,该命令也可以运行;它不要求先有一次通过的审核,因为修复提交 push 后一定会对新 head 重新完整审核,修复动作本身不会直接批准合并。
|
||||
|
||||
仅处理当前 head 未变化且 PR 分支位于同一仓库的情况;外部 fork、旧 head、非冲突状态和未通过审核的 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` 并重新完整审核,不会把修复前的结论直接当作批准。
|
||||
@@ -134,7 +144,6 @@ workflow 自动获得 `github.token`,无需额外创建名为 `GITHUB_TOKEN`
|
||||
|
||||
workflow 声明以下权限:
|
||||
|
||||
- `actions: write`:保存和恢复 Actions cache。
|
||||
- `contents: write`:可选自动合并和仓库操作。
|
||||
- `pull-requests: write`:列出 PR、提交 review 和合并。
|
||||
- `issues: write`:列出 Issue/PR、管理标签和发布评论。
|
||||
@@ -143,7 +152,6 @@ workflow 声明以下权限:
|
||||
|
||||
GitHub App 建议配置以下 Repository permissions:
|
||||
|
||||
- Actions:Read and write
|
||||
- Contents:Read and write
|
||||
- Pull requests:Read and write
|
||||
- Issues:Read and write
|
||||
@@ -160,7 +168,7 @@ GitHub App 建议配置以下 Repository permissions:
|
||||
|
||||
GitHub Actions Secret 和 Variable 名称不能以 `GITHUB_` 开头,所以使用上述 `GH_APP_*` 名称。
|
||||
|
||||
GitHub App 和 workflow token 在拥有对应权限时都可以列出 Issue、PR 和标签。Actions cache 由 workflow 的 `github.token` 和 `actions/cache` 管理,不会在 PR 关闭时由 App 主动删除。
|
||||
GitHub App 和 workflow token 在拥有对应权限时都可以列出 Issue、PR 和标签。R2 缓存与 GitHub App 权限无关,也不会在 PR 关闭时主动删除。
|
||||
|
||||
## 在其他仓库中复用
|
||||
|
||||
@@ -178,6 +186,8 @@ secrets:
|
||||
GH_APP_ID: ${{ secrets.GH_APP_ID }}
|
||||
GH_APP_PRIVATE_KEY: ${{ secrets.GH_APP_PRIVATE_KEY }}
|
||||
GH_APP_INSTALLATION_ID: ${{ secrets.GH_APP_INSTALLATION_ID }}
|
||||
R2_ACCESS_KEY_ID: ${{ secrets.R2_ACCESS_KEY_ID }}
|
||||
R2_SECRET_ACCESS_KEY: ${{ secrets.R2_SECRET_ACCESS_KEY }}
|
||||
```
|
||||
|
||||
完整的 `with:` 输入和 Repository Variables 映射请参考仓库内的 wrapper workflow。
|
||||
@@ -192,6 +202,16 @@ secrets:
|
||||
|
||||
机器人会按照仓库当前的 `REVIEW_STRICTNESS` 对最新完整 PR 重新审核。只有具有 `write`、`maintain` 或 `admin` 权限的用户可以触发;旧 `/lenient-check` 命令不再生效。
|
||||
|
||||
## 手动解决冲突
|
||||
|
||||
有资格的仓库用户可以评论精确命令:
|
||||
|
||||
```text
|
||||
/conflict
|
||||
```
|
||||
|
||||
只有当 GitHub 报告当前开放 PR 存在冲突,且 head 分支属于同一个仓库时才会尝试修复。机器人不会向外部 fork push。它会运行与自动修复相同的可信验证命令和第二次 goose 最终确认;两者成功且远端 head 未变化时才会创建普通 commit 并 push。
|
||||
|
||||
## 本地开发
|
||||
|
||||
需要 Node.js 22 至 25。PR comment Agent 的全工具集成测试还需要可用的 Docker daemon。
|
||||
|
||||
@@ -34,9 +34,9 @@ Use repository Actions variables to customize a caller repository:
|
||||
|
||||
To make `require_approval` or `reject` prevent manual merges, add the `ghbot review` check as a required status check in the target branch's ruleset or branch protection settings. Without that repository rule, ghbot still reports `action_required`, but GitHub may allow an administrator or collaborator to merge manually.
|
||||
|
||||
### Incremental review cache
|
||||
### Incremental review cache in Cloudflare R2
|
||||
|
||||
Each successful review stores this metadata in GitHub Actions cache:
|
||||
When Cloudflare R2 is configured, each successful review stores this metadata in the private bucket:
|
||||
|
||||
- repository and PR number
|
||||
- reviewed head SHA and timestamp
|
||||
@@ -44,16 +44,24 @@ Each successful review stores this metadata in GitHub Actions cache:
|
||||
|
||||
When a new commit triggers `synchronize`, or PR metadata/base changes trigger `edited`, the latest cache for that PR is restored. goose receives an earlier-head result plus the current complete PR patch, revalidates old findings, removes fixed findings, and checks the newest content. The previous merge decision is never reused without a fresh review. An `edited` event on the same head still runs a fresh complete review so title, description, and base-branch changes are respected.
|
||||
|
||||
Cache keys are isolated by repository ID and PR number. Closing or merging a PR does not proactively delete its Actions cache; GitHub's normal cache retention policy removes old entries. Cache data contains no API keys, full diff, or prompt.
|
||||
Objects are isolated by repository ID and PR number. `latest.json` accelerates the next review, while `reviews/<head-sha>.json` preserves each successful head result. Closing or merging a PR does not proactively delete these objects. Cache data contains no API keys, full diff, or prompt.
|
||||
|
||||
Configure all of these together:
|
||||
|
||||
- Actions secrets: `R2_ACCESS_KEY_ID`, `R2_SECRET_ACCESS_KEY`
|
||||
- Repository variables: `R2_ENDPOINT`, `R2_BUCKET_NAME`
|
||||
- Optional repository variable: `R2_PREFIX`, a safe object-key namespace such as `forum-114614`
|
||||
|
||||
Use a dedicated R2 token limited to read/write objects in this bucket. ghbot validates restored content and repository/PR identity before using it. R2 credentials are available only to the host process and are never forwarded to goose containers, PR validation commands, or git subprocesses. If R2 is absent or temporarily unavailable, review continues without persistent history.
|
||||
|
||||
### Self-improving repository knowledge cache
|
||||
|
||||
ghbot can retain a concise repository knowledge file in GitHub Actions cache. It is isolated by repository ID and separate from each PR review cache, so it survives PR close and merge events. Automatic review can use durable facts such as architecture, supported environments, trusted validation commands, conventions, and recurring pitfalls.
|
||||
ghbot can retain a concise repository knowledge file in the same private R2 bucket. It is isolated by repository ID and separate from each PR review cache, so it survives PR close and merge events. Automatic review can use durable facts such as architecture, supported environments, trusted validation commands, conventions, and recurring pitfalls.
|
||||
|
||||
- `REPOSITORY_KNOWLEDGE_ENABLED`: restore and use repository knowledge; default `true`.
|
||||
- `REPOSITORY_KNOWLEDGE_WRITE`: allow an authorized `@bot` goose Agent to improve the cached knowledge; default `false`.
|
||||
|
||||
The Agent edits only a scratch copy at `.ghbot/repository-knowledge.md`. ghbot validates the result, rejects credentials/private keys and content over 32 KiB, then copies it to `.ghbot-knowledge/repository.md` in the reusable-workflow runtime. `actions/cache` persists that file under a repository-scoped key. It is never committed to the caller repository, and the Agent still receives no GitHub credentials.
|
||||
The Agent edits only a scratch copy at `.ghbot/repository-knowledge.md`. ghbot validates the result, rejects credentials/private keys and content over 32 KiB, then persists the runtime copy to a repository-scoped R2 object. It is never committed to the caller repository, and the Agent receives neither GitHub nor R2 credentials.
|
||||
|
||||
## Issue and PR triage
|
||||
|
||||
@@ -94,6 +102,8 @@ When repository knowledge writing is enabled, the Agent may improve its scratch
|
||||
|
||||
Set `AUTO_RESOLVE_CONFLICTS=true` to allow goose to repair a PR that passed review but GitHub reports as `mergeable=false` with `mergeable_state=dirty`. This is independent of `AUTO_MERGE`; conflict repair can be enabled while automatic merging remains disabled.
|
||||
|
||||
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 only to a current-head PR branch in the same repository. External forks, stale heads, non-dirty states, 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.
|
||||
@@ -126,7 +136,6 @@ The workflow always receives `github.token`, so no `GITHUB_TOKEN` repository sec
|
||||
|
||||
Workflow permissions:
|
||||
|
||||
- `actions: write`: save and restore Actions cache.
|
||||
- `contents: write`: optional merge and repository operations.
|
||||
- `pull-requests: write`: list PRs, create reviews, and merge.
|
||||
- `issues: write`: list issues/PRs, add labels, create labels, and post comments.
|
||||
@@ -135,7 +144,6 @@ Workflow permissions:
|
||||
|
||||
For a GitHub App, configure these repository permissions:
|
||||
|
||||
- Actions: read and write
|
||||
- Contents: read and write
|
||||
- Pull requests: read and write
|
||||
- Issues: read and write
|
||||
@@ -168,6 +176,8 @@ secrets:
|
||||
GH_APP_ID: ${{ secrets.GH_APP_ID }}
|
||||
GH_APP_PRIVATE_KEY: ${{ secrets.GH_APP_PRIVATE_KEY }}
|
||||
GH_APP_INSTALLATION_ID: ${{ secrets.GH_APP_INSTALLATION_ID }}
|
||||
R2_ACCESS_KEY_ID: ${{ secrets.R2_ACCESS_KEY_ID }}
|
||||
R2_SECRET_ACCESS_KEY: ${{ secrets.R2_SECRET_ACCESS_KEY }}
|
||||
```
|
||||
|
||||
See the checked-in wrapper for all `with:` inputs and repository-variable mappings.
|
||||
@@ -182,6 +192,16 @@ An eligible repository user can comment:
|
||||
|
||||
The bot reruns the complete current PR review using the repository's configured `REVIEW_STRICTNESS`. Only users with `write`, `maintain`, or `admin` permission can request it. The old `/lenient-check` command is no longer accepted.
|
||||
|
||||
## Manual conflict repair
|
||||
|
||||
An eligible repository user can comment the exact command:
|
||||
|
||||
```text
|
||||
/conflict
|
||||
```
|
||||
|
||||
The bot attempts conflict repair only when GitHub reports the current open PR as conflicted and its head branch belongs to the same repository. External forks are never pushed. It runs the same configured validation and separate final goose confirmation used by automatic repair, then pushes a normal commit only if both succeed and the head has not changed.
|
||||
|
||||
## Local development
|
||||
|
||||
```bash
|
||||
|
||||
Generated
+402
@@ -8,6 +8,7 @@
|
||||
"name": "ghbot",
|
||||
"version": "0.1.0",
|
||||
"dependencies": {
|
||||
"@aws-sdk/client-s3": "^3.864.0",
|
||||
"@octokit/auth-app": "^8.2.0",
|
||||
"@octokit/rest": "^21.0.2",
|
||||
"dotenv": "^16.4.7",
|
||||
@@ -23,6 +24,314 @@
|
||||
"node": ">=22 <26"
|
||||
}
|
||||
},
|
||||
"node_modules/@aws-sdk/checksums": {
|
||||
"version": "3.1000.27",
|
||||
"resolved": "https://registry.npmmirror.com/@aws-sdk/checksums/-/checksums-3.1000.27.tgz",
|
||||
"integrity": "sha512-insWOqKKNUrbN/dohEG7BJ0U5GkyqhjbMb/NHNaLUtq+7my2M8C4EnZZZoxMmXRqCC+P9dEr+KyJA2JGGzoKLg==",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@aws-sdk/core": "^3.977.7",
|
||||
"@aws-sdk/types": "^3.974.3",
|
||||
"@smithy/core": "^3.31.1",
|
||||
"@smithy/types": "^4.16.1",
|
||||
"tslib": "^2.6.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=20.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@aws-sdk/client-s3": {
|
||||
"version": "3.1109.0",
|
||||
"resolved": "https://registry.npmmirror.com/@aws-sdk/client-s3/-/client-s3-3.1109.0.tgz",
|
||||
"integrity": "sha512-iPWzBeGkAe5H5+dBBGCOdIT4uMhpu12OK+nFnDzjvOChVnHIws4LeoG7Yl0kJHSRWZnNEkVcF4vQYTJny0e5xA==",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@aws-sdk/checksums": "^3.1000.27",
|
||||
"@aws-sdk/core": "^3.977.7",
|
||||
"@aws-sdk/credential-provider-node": "^3.972.79",
|
||||
"@aws-sdk/middleware-sdk-s3": "^3.972.73",
|
||||
"@aws-sdk/signature-v4-multi-region": "^3.996.44",
|
||||
"@aws-sdk/types": "^3.974.3",
|
||||
"@smithy/core": "^3.31.1",
|
||||
"@smithy/fetch-http-handler": "^5.6.13",
|
||||
"@smithy/node-http-handler": "^4.9.13",
|
||||
"@smithy/types": "^4.16.1",
|
||||
"tslib": "^2.6.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=20.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@aws-sdk/core": {
|
||||
"version": "3.977.7",
|
||||
"resolved": "https://registry.npmmirror.com/@aws-sdk/core/-/core-3.977.7.tgz",
|
||||
"integrity": "sha512-I88Iov89NVmjSmJLKSv7Cn9M2J+a2942OkA8nZCbz+sl4ZeY4zEOcoLOrbt1GRfQ8zEQKnjAJdXixA3J/p1fDQ==",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@aws-sdk/types": "^3.974.3",
|
||||
"@aws-sdk/xml-builder": "^3.972.38",
|
||||
"@aws/lambda-invoke-store": "^0.3.0",
|
||||
"@smithy/core": "^3.31.1",
|
||||
"@smithy/signature-v4": "^5.6.12",
|
||||
"@smithy/types": "^4.16.1",
|
||||
"bowser": "^2.11.0",
|
||||
"tslib": "^2.6.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=20.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@aws-sdk/credential-provider-env": {
|
||||
"version": "3.972.68",
|
||||
"resolved": "https://registry.npmmirror.com/@aws-sdk/credential-provider-env/-/credential-provider-env-3.972.68.tgz",
|
||||
"integrity": "sha512-2a20A/IdNOwUvaDq91iqqS7BA0XlNMfW3iLGZGZLJv0EbUqhSxB0PIx4rQQqssvWj1uXImb3/UCCdHz/+1dOiA==",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@aws-sdk/core": "^3.977.7",
|
||||
"@aws-sdk/types": "^3.974.3",
|
||||
"@smithy/core": "^3.31.1",
|
||||
"@smithy/types": "^4.16.1",
|
||||
"tslib": "^2.6.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=20.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@aws-sdk/credential-provider-http": {
|
||||
"version": "3.972.70",
|
||||
"resolved": "https://registry.npmmirror.com/@aws-sdk/credential-provider-http/-/credential-provider-http-3.972.70.tgz",
|
||||
"integrity": "sha512-0yRem2Fs52r/Nn6UAqIlpjexfaYj8ziEozOe9tamtAVT/5bzFLKx8O2r7MaRqgS3hGKHIa1Jij9nKHSsNnb04A==",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@aws-sdk/core": "^3.977.7",
|
||||
"@aws-sdk/types": "^3.974.3",
|
||||
"@smithy/core": "^3.31.1",
|
||||
"@smithy/fetch-http-handler": "^5.6.13",
|
||||
"@smithy/node-http-handler": "^4.9.13",
|
||||
"@smithy/types": "^4.16.1",
|
||||
"tslib": "^2.6.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=20.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@aws-sdk/credential-provider-ini": {
|
||||
"version": "3.973.13",
|
||||
"resolved": "https://registry.npmmirror.com/@aws-sdk/credential-provider-ini/-/credential-provider-ini-3.973.13.tgz",
|
||||
"integrity": "sha512-2M39DE02XpYYaSWYk/4AsImXYUU/1L2xmTMLUpMMWq7DfLv191/vCRy3baKtdr45AkJQyVgSjmuVOLm15SwrRQ==",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@aws-sdk/core": "^3.977.7",
|
||||
"@aws-sdk/credential-provider-env": "^3.972.68",
|
||||
"@aws-sdk/credential-provider-http": "^3.972.70",
|
||||
"@aws-sdk/credential-provider-login": "^3.972.75",
|
||||
"@aws-sdk/credential-provider-process": "^3.972.68",
|
||||
"@aws-sdk/credential-provider-sso": "^3.973.12",
|
||||
"@aws-sdk/credential-provider-web-identity": "^3.972.74",
|
||||
"@aws-sdk/nested-clients": "^3.997.42",
|
||||
"@aws-sdk/types": "^3.974.3",
|
||||
"@smithy/core": "^3.31.1",
|
||||
"@smithy/credential-provider-imds": "^4.4.16",
|
||||
"@smithy/types": "^4.16.1",
|
||||
"tslib": "^2.6.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=20.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@aws-sdk/credential-provider-login": {
|
||||
"version": "3.972.75",
|
||||
"resolved": "https://registry.npmmirror.com/@aws-sdk/credential-provider-login/-/credential-provider-login-3.972.75.tgz",
|
||||
"integrity": "sha512-jaTESuJlQsoUZ44f/i2puyPt8VlF/dMMJ9HM3cStYtk7eKX4N9UWi83OLixUkoOJH3BwWlPLCq9YIK9nfWhVBg==",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@aws-sdk/core": "^3.977.7",
|
||||
"@aws-sdk/nested-clients": "^3.997.42",
|
||||
"@aws-sdk/types": "^3.974.3",
|
||||
"@smithy/core": "^3.31.1",
|
||||
"@smithy/types": "^4.16.1",
|
||||
"tslib": "^2.6.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=20.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@aws-sdk/credential-provider-node": {
|
||||
"version": "3.972.79",
|
||||
"resolved": "https://registry.npmmirror.com/@aws-sdk/credential-provider-node/-/credential-provider-node-3.972.79.tgz",
|
||||
"integrity": "sha512-RIw5dof1EHkWubrZzPC941CDtnFG1iAXsxbFgLkhdYZXHc4icU13c/uxSMI0J5eUx9bxa7LjfpdjfClBB1QsDA==",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@aws-sdk/credential-provider-env": "^3.972.68",
|
||||
"@aws-sdk/credential-provider-http": "^3.972.70",
|
||||
"@aws-sdk/credential-provider-ini": "^3.973.13",
|
||||
"@aws-sdk/credential-provider-process": "^3.972.68",
|
||||
"@aws-sdk/credential-provider-sso": "^3.973.12",
|
||||
"@aws-sdk/credential-provider-web-identity": "^3.972.74",
|
||||
"@aws-sdk/types": "^3.974.3",
|
||||
"@smithy/core": "^3.31.1",
|
||||
"@smithy/credential-provider-imds": "^4.4.16",
|
||||
"@smithy/types": "^4.16.1",
|
||||
"tslib": "^2.6.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=20.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@aws-sdk/credential-provider-process": {
|
||||
"version": "3.972.68",
|
||||
"resolved": "https://registry.npmmirror.com/@aws-sdk/credential-provider-process/-/credential-provider-process-3.972.68.tgz",
|
||||
"integrity": "sha512-nLP3Pda2MQTFJ25hKBMmUuB9Uv+bTZQNlufbeCwklP549Vwnkd8bRLJoCKp5k6xjmdyptrPrOfGOhN0mKuca8A==",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@aws-sdk/core": "^3.977.7",
|
||||
"@aws-sdk/types": "^3.974.3",
|
||||
"@smithy/core": "^3.31.1",
|
||||
"@smithy/types": "^4.16.1",
|
||||
"tslib": "^2.6.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=20.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@aws-sdk/credential-provider-sso": {
|
||||
"version": "3.973.12",
|
||||
"resolved": "https://registry.npmmirror.com/@aws-sdk/credential-provider-sso/-/credential-provider-sso-3.973.12.tgz",
|
||||
"integrity": "sha512-EmgyyHn+f9WCcelp3L/vci+LGbX8GigWaVphRArjVo5Pktkr9YnLy/mQ6VDkDyBD72dtfRNTgHmD2ts4rTDXKQ==",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@aws-sdk/core": "^3.977.7",
|
||||
"@aws-sdk/nested-clients": "^3.997.42",
|
||||
"@aws-sdk/token-providers": "3.1108.0",
|
||||
"@aws-sdk/types": "^3.974.3",
|
||||
"@smithy/core": "^3.31.1",
|
||||
"@smithy/types": "^4.16.1",
|
||||
"tslib": "^2.6.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=20.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@aws-sdk/credential-provider-web-identity": {
|
||||
"version": "3.972.74",
|
||||
"resolved": "https://registry.npmmirror.com/@aws-sdk/credential-provider-web-identity/-/credential-provider-web-identity-3.972.74.tgz",
|
||||
"integrity": "sha512-0YfczxGXF3RjGj8z7QG/Ho2HnLGKDHfPSHiTs47UU1U/+mmwISDN+rvGKt2zh+3FX8NdT4xd95LGBGyhQw2dgQ==",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@aws-sdk/core": "^3.977.7",
|
||||
"@aws-sdk/nested-clients": "^3.997.42",
|
||||
"@aws-sdk/types": "^3.974.3",
|
||||
"@smithy/core": "^3.31.1",
|
||||
"@smithy/types": "^4.16.1",
|
||||
"tslib": "^2.6.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=20.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@aws-sdk/middleware-sdk-s3": {
|
||||
"version": "3.972.73",
|
||||
"resolved": "https://registry.npmmirror.com/@aws-sdk/middleware-sdk-s3/-/middleware-sdk-s3-3.972.73.tgz",
|
||||
"integrity": "sha512-oy7sRA5HvHcAvkcKX6F8RI240jcOf3c8y/Gqjs9qemIibdKQqGBIi0uwa+47ZRYqGLpdEO28TQU4G73yUzo06Q==",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@aws-sdk/core": "^3.977.7",
|
||||
"@aws-sdk/signature-v4-multi-region": "^3.996.44",
|
||||
"@aws-sdk/types": "^3.974.3",
|
||||
"@smithy/core": "^3.31.1",
|
||||
"@smithy/types": "^4.16.1",
|
||||
"tslib": "^2.6.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=20.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@aws-sdk/nested-clients": {
|
||||
"version": "3.997.42",
|
||||
"resolved": "https://registry.npmmirror.com/@aws-sdk/nested-clients/-/nested-clients-3.997.42.tgz",
|
||||
"integrity": "sha512-XWRyon2MTHXD/zMoo0Mbge6Vwf+iE0qQaM/RyGO6NfZ9WukCFiQL27nQVZjYy2JwSIg+iXZxKOX95OBXqlSM4w==",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@aws-sdk/core": "^3.977.7",
|
||||
"@aws-sdk/signature-v4-multi-region": "^3.996.44",
|
||||
"@aws-sdk/types": "^3.974.3",
|
||||
"@smithy/core": "^3.31.1",
|
||||
"@smithy/fetch-http-handler": "^5.6.13",
|
||||
"@smithy/node-http-handler": "^4.9.13",
|
||||
"@smithy/types": "^4.16.1",
|
||||
"tslib": "^2.6.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=20.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@aws-sdk/signature-v4-multi-region": {
|
||||
"version": "3.996.44",
|
||||
"resolved": "https://registry.npmmirror.com/@aws-sdk/signature-v4-multi-region/-/signature-v4-multi-region-3.996.44.tgz",
|
||||
"integrity": "sha512-ZSfQ35Qn4MhSY+A0Whyr+KBx+wJKZUyBsOrjB2pSHOafRzbFe47T8XcXM8hZqUAC69qnqIy0C9ArxTuud0CC2w==",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@aws-sdk/types": "^3.974.3",
|
||||
"@smithy/signature-v4": "^5.6.12",
|
||||
"@smithy/types": "^4.16.1",
|
||||
"tslib": "^2.6.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=20.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@aws-sdk/token-providers": {
|
||||
"version": "3.1108.0",
|
||||
"resolved": "https://registry.npmmirror.com/@aws-sdk/token-providers/-/token-providers-3.1108.0.tgz",
|
||||
"integrity": "sha512-rI80zxDxGJ6904eC/YbjkdjY6JdaZvQ01kOmrMvw7cFQGIHo27fhnIVbMSVDS4T6foQImjxYSRoOu/uSJscXDw==",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@aws-sdk/core": "^3.977.7",
|
||||
"@aws-sdk/nested-clients": "^3.997.42",
|
||||
"@aws-sdk/types": "^3.974.3",
|
||||
"@smithy/core": "^3.31.1",
|
||||
"@smithy/types": "^4.16.1",
|
||||
"tslib": "^2.6.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=20.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@aws-sdk/types": {
|
||||
"version": "3.974.3",
|
||||
"resolved": "https://registry.npmmirror.com/@aws-sdk/types/-/types-3.974.3.tgz",
|
||||
"integrity": "sha512-ECAqfpNsef+7MO8qtR0h9KcFIBAygaE7Cm6UOiQl+ft+uVap+1G7bNEjs4mdJE2OnA4m6k7i8peH8uGIAsOMGw==",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@smithy/types": "^4.16.1",
|
||||
"tslib": "^2.6.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=20.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@aws-sdk/xml-builder": {
|
||||
"version": "3.972.38",
|
||||
"resolved": "https://registry.npmmirror.com/@aws-sdk/xml-builder/-/xml-builder-3.972.38.tgz",
|
||||
"integrity": "sha512-grf7mzfVxBS5AlsuTvBN7uDpzqohFww9fRPCO+EBSUdvtsYMcPSKdz54h/7XiscqNcUM1Ae1MF7JLHmiYYuzbQ==",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@smithy/types": "^4.16.1",
|
||||
"tslib": "^2.6.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=20.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@aws/lambda-invoke-store": {
|
||||
"version": "0.3.0",
|
||||
"resolved": "https://registry.npmmirror.com/@aws/lambda-invoke-store/-/lambda-invoke-store-0.3.0.tgz",
|
||||
"integrity": "sha512-sl4Bm6yiMNYrZKkqqDFWN0UfnWhlS8ivKxrYl+6t0gCLrqr8y3B2IqZZbFRkfaVVp7C/baApyh71P+LeE1A2sQ==",
|
||||
"license": "Apache-2.0",
|
||||
"engines": {
|
||||
"node": ">=18.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@esbuild/aix-ppc64": {
|
||||
"version": "0.27.0",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/aix-ppc64/-/aix-ppc64-0.27.0.tgz",
|
||||
@@ -1115,6 +1424,87 @@
|
||||
"integrity": "sha512-k2ENnmBugE/rzQfEcdWHcCY+/FM3VLzH9cYEsbdsoqrvzAKRhUZeRNhAZvB8OitQJ1TBed3yqWtdjzS6wJKBwg==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@smithy/core": {
|
||||
"version": "3.32.0",
|
||||
"resolved": "https://registry.npmmirror.com/@smithy/core/-/core-3.32.0.tgz",
|
||||
"integrity": "sha512-NAiCSC78fzbNIEWoheoF74Ob5ZorLijCHpMY26Fqvqg/+9LuyIqMfHDg2p8Yk1rqOyowtiL3y7WX0AW+teL6zw==",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@smithy/types": "^4.17.0",
|
||||
"tslib": "^2.6.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=18.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@smithy/credential-provider-imds": {
|
||||
"version": "4.5.0",
|
||||
"resolved": "https://registry.npmmirror.com/@smithy/credential-provider-imds/-/credential-provider-imds-4.5.0.tgz",
|
||||
"integrity": "sha512-2jsPi+7Zv2hSzD9IXR9D7DTqSn7mv4XalzRm+bESh53jiaUS3NKEUbpQFTJP0HhQy9qzZvluxQ3yS24zdRrqsA==",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@smithy/core": "^3.32.0",
|
||||
"@smithy/types": "^4.17.0",
|
||||
"tslib": "^2.6.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=18.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@smithy/fetch-http-handler": {
|
||||
"version": "5.7.0",
|
||||
"resolved": "https://registry.npmmirror.com/@smithy/fetch-http-handler/-/fetch-http-handler-5.7.0.tgz",
|
||||
"integrity": "sha512-W/exA8T0LEzCQtJ02w4IzaEQPIspgarqZprb7W8FwnYiDowgCrjl2fTQ6FvuSSUnJORuepBF81abmBJwqh+0XQ==",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@smithy/core": "^3.32.0",
|
||||
"@smithy/types": "^4.17.0",
|
||||
"tslib": "^2.6.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=18.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@smithy/node-http-handler": {
|
||||
"version": "4.10.0",
|
||||
"resolved": "https://registry.npmmirror.com/@smithy/node-http-handler/-/node-http-handler-4.10.0.tgz",
|
||||
"integrity": "sha512-nrh7VxqzPQS/ip1hS293aI/OAWDWARQvjUxCfuKhyrfHa2gTdk28066RNeWLI1uuoHXaKAkOF8IcSAHuOp0+SA==",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@smithy/core": "^3.32.0",
|
||||
"@smithy/types": "^4.17.0",
|
||||
"tslib": "^2.6.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=18.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@smithy/signature-v4": {
|
||||
"version": "5.7.0",
|
||||
"resolved": "https://registry.npmmirror.com/@smithy/signature-v4/-/signature-v4-5.7.0.tgz",
|
||||
"integrity": "sha512-hCynhm22wMJ8wTF9crcwu8mxggtUrSLLJgDcGUvYFBqpofxycYJCGKOMYg4xtPPFtgNiDJSYmhsWLTrcU/g59Q==",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@smithy/core": "^3.32.0",
|
||||
"@smithy/types": "^4.17.0",
|
||||
"tslib": "^2.6.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=18.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@smithy/types": {
|
||||
"version": "4.17.0",
|
||||
"resolved": "https://registry.npmmirror.com/@smithy/types/-/types-4.17.0.tgz",
|
||||
"integrity": "sha512-Aw4joiM0ZdErpo39lCj8phT2lxoiKZV+KZzBxnnQhWVtU2Is/WffQSL04uUWRcXUse9Ln8vXZK6V/FwqRVnQpg==",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"tslib": "^2.6.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=18.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/node": {
|
||||
"version": "22.19.19",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-22.19.19.tgz",
|
||||
@@ -1140,6 +1530,12 @@
|
||||
"integrity": "sha512-Nik3Sc0ncrMK4UUdXQmAnRtzmNQTAAXmXIopizwZ1W1t8QmfJj+zL4OA2I7XPTPW5z5TDqv4hRo/JzouDJnX3A==",
|
||||
"license": "Apache-2.0"
|
||||
},
|
||||
"node_modules/bowser": {
|
||||
"version": "2.14.1",
|
||||
"resolved": "https://registry.npmmirror.com/bowser/-/bowser-2.14.1.tgz",
|
||||
"integrity": "sha512-tzPjzCxygAKWFOJP011oxFHs57HzIhOEracIgAePE4pqB3LikALKnSzUyU4MGs9/iCEUuHlAJTjTc5M+u7YEGg==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/content-type": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/content-type/-/content-type-2.0.0.tgz",
|
||||
@@ -1389,6 +1785,12 @@
|
||||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/tslib": {
|
||||
"version": "2.8.1",
|
||||
"resolved": "https://registry.npmmirror.com/tslib/-/tslib-2.8.1.tgz",
|
||||
"integrity": "sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==",
|
||||
"license": "0BSD"
|
||||
},
|
||||
"node_modules/tsx": {
|
||||
"version": "4.21.0",
|
||||
"resolved": "https://registry.npmjs.org/tsx/-/tsx-4.21.0.tgz",
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
"typecheck": "tsc -p tsconfig.json --noEmit"
|
||||
},
|
||||
"dependencies": {
|
||||
"@aws-sdk/client-s3": "^3.864.0",
|
||||
"@octokit/auth-app": "^8.2.0",
|
||||
"@octokit/rest": "^21.0.2",
|
||||
"dotenv": "^16.4.7",
|
||||
|
||||
@@ -7,14 +7,17 @@ import { processPullRequestChat } from "../chat/processor.js";
|
||||
import { processIssueTriage, processPullRequestTriage } from "../triage/processor.js";
|
||||
import { deleteLocalReviewCache } from "../review/cache.js";
|
||||
import {
|
||||
processConflictComment,
|
||||
processRecheckComment,
|
||||
processPullRequest,
|
||||
processScheduledPendingMerges,
|
||||
processPullRequestReviewApproval,
|
||||
shouldReviewPullRequest
|
||||
} from "../review/processor.js";
|
||||
import { restorePersistentCache, savePersistentCache } from "../storage/cacheStore.js";
|
||||
|
||||
type GitHubRepository = {
|
||||
id?: number;
|
||||
name: string;
|
||||
owner: {
|
||||
login: string;
|
||||
@@ -82,19 +85,34 @@ async function main(): Promise<void> {
|
||||
? buildPayloadFromWorkflowCallEnv(workflowCallEventName)
|
||||
: readPayloadFromGitHubEventPath();
|
||||
const repository = payload.repository;
|
||||
const github = await createGitHubCredentials({
|
||||
owner: repository.owner.login,
|
||||
repo: repository.name
|
||||
});
|
||||
const octokit = github.octokit;
|
||||
const eventName = workflowCallEventName ?? process.env.GITHUB_EVENT_NAME;
|
||||
|
||||
if (!eventName) {
|
||||
throw new Error("GITHUB_EVENT_NAME is required.");
|
||||
}
|
||||
|
||||
const pullNumberForCache = getPullNumberForCache(eventName, payload);
|
||||
const persistentCache = {
|
||||
repositoryId: process.env.GHBOT_REPOSITORY_ID || String(repository.id ?? ""),
|
||||
owner: repository.owner.login,
|
||||
repo: repository.name,
|
||||
pullNumber: pullNumberForCache,
|
||||
prefix: config.r2Prefix
|
||||
};
|
||||
await restorePersistentCache(persistentCache).catch((error: unknown) => {
|
||||
logger.warn({ error, eventName }, "Persistent R2 cache restore failed; continuing without it.");
|
||||
});
|
||||
|
||||
const github = await createGitHubCredentials({
|
||||
owner: repository.owner.login,
|
||||
repo: repository.name
|
||||
});
|
||||
const octokit = github.octokit;
|
||||
|
||||
logger.info({ eventName }, "Handling GitHub Actions review event.");
|
||||
|
||||
let eventFailed = false;
|
||||
try {
|
||||
if (eventName === "pull_request_target") {
|
||||
const prPayload = payload as PullRequestPayload;
|
||||
const ref = {
|
||||
@@ -171,6 +189,14 @@ async function main(): Promise<void> {
|
||||
commentBody: commentPayload.comment.body,
|
||||
gitToken: github.token
|
||||
});
|
||||
await processConflictComment(octokit, {
|
||||
owner: commentPayload.repository.owner.login,
|
||||
repo: commentPayload.repository.name,
|
||||
pullNumber: commentPayload.issue.number,
|
||||
commenterLogin: commentPayload.comment.user.login,
|
||||
commentBody: commentPayload.comment.body,
|
||||
gitToken: github.token
|
||||
});
|
||||
await processPullRequestChat(octokit, {
|
||||
owner: commentPayload.repository.owner.login,
|
||||
repo: commentPayload.repository.name,
|
||||
@@ -211,6 +237,33 @@ async function main(): Promise<void> {
|
||||
}
|
||||
|
||||
logger.warn({ eventName }, "Unhandled GitHub Actions event.");
|
||||
} catch (error) {
|
||||
eventFailed = true;
|
||||
throw error;
|
||||
} finally {
|
||||
if (!eventFailed) {
|
||||
await savePersistentCache(persistentCache).catch((error: unknown) => {
|
||||
logger.warn({ error, eventName }, "Persistent R2 cache save failed; review results remain valid for this run.");
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function getPullNumberForCache(
|
||||
eventName: string,
|
||||
payload: PullRequestPayload | IssuePayload | IssueCommentPayload | PullRequestReviewPayload | ScheduledPayload
|
||||
): number | undefined {
|
||||
if (eventName === "pull_request_target") {
|
||||
return (payload as PullRequestPayload).pull_request.number;
|
||||
}
|
||||
if (eventName === "issue_comment") {
|
||||
const commentPayload = payload as IssueCommentPayload;
|
||||
return commentPayload.issue.pull_request ? commentPayload.issue.number : undefined;
|
||||
}
|
||||
if (eventName === "pull_request_review") {
|
||||
return (payload as PullRequestReviewPayload).pull_request.number;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function readPayloadFromGitHubEventPath(): PullRequestPayload | IssuePayload | IssueCommentPayload | PullRequestReviewPayload | ScheduledPayload {
|
||||
@@ -233,6 +286,7 @@ function buildPayloadFromWorkflowCallEnv(eventName: string): PullRequestPayload
|
||||
}
|
||||
|
||||
const repository = {
|
||||
id: Number(process.env.GHBOT_REPOSITORY_ID) || undefined,
|
||||
name: repo,
|
||||
owner: {
|
||||
login: owner
|
||||
|
||||
@@ -223,7 +223,7 @@ function buildChatPrompt(input: {
|
||||
? [
|
||||
`Trusted repository knowledge is available at ${REPOSITORY_KNOWLEDGE_SCRATCH_PATH}. Read it when useful.`,
|
||||
input.repositoryKnowledgeWrite
|
||||
? "You may improve that knowledge file when you discover a verified, durable repository fact. The repository can evolve: actively revise or remove old entries when current code, tests, or configuration prove that they are outdated, replaced, contradictory, or no longer true; do not merely append forever. Keep it concise and record only architecture, supported environments, commands, conventions, and recurring pitfalls. Never store credentials, personal data, speculative claims, temporary PR state, or instructions that weaken safety. The host will validate it and persist it only in repository-scoped GitHub Actions cache after this run; it will not be committed to the repository."
|
||||
? "You may improve that knowledge file when you discover a verified, durable repository fact. The repository can evolve: actively revise or remove old entries when current code, tests, or configuration prove that they are outdated, replaced, contradictory, or no longer true; do not merely append forever. Keep it concise and record only architecture, supported environments, commands, conventions, and recurring pitfalls. Never store credentials, personal data, speculative claims, temporary PR state, or instructions that weaken safety. The host will validate it and persist it only in repository-scoped private object storage after this run; it will not be committed to the repository."
|
||||
: "Treat that knowledge file as read-only. Repository knowledge writing is disabled by configuration."
|
||||
]
|
||||
: ["No trusted repository knowledge file is enabled for this run."]),
|
||||
|
||||
@@ -75,6 +75,11 @@ const configSchema = z.object({
|
||||
reviewBranches: csvListWithDefault([]),
|
||||
repositoryKnowledgeEnabled: envBoolean.default(true),
|
||||
repositoryKnowledgeWrite: envBoolean.default(false),
|
||||
r2Endpoint: optionalString,
|
||||
r2BucketName: optionalString,
|
||||
r2Prefix: optionalString,
|
||||
r2AccessKeyId: optionalString,
|
||||
r2SecretAccessKey: optionalString,
|
||||
triageEnabled: envBoolean.default(true),
|
||||
triageLabels: csvListWithDefault(["bug", "enhancement", "documentation", "question", "maintenance"])
|
||||
.refine((labels) => labels.length > 0, "TRIAGE_LABELS must contain at least one label."),
|
||||
@@ -108,6 +113,11 @@ export const config = configSchema.parse({
|
||||
reviewBranches: process.env.REVIEW_BRANCHES,
|
||||
repositoryKnowledgeEnabled: process.env.REPOSITORY_KNOWLEDGE_ENABLED,
|
||||
repositoryKnowledgeWrite: process.env.REPOSITORY_KNOWLEDGE_WRITE,
|
||||
r2Endpoint: process.env.R2_ENDPOINT,
|
||||
r2BucketName: process.env.R2_BUCKET_NAME,
|
||||
r2Prefix: process.env.R2_PREFIX,
|
||||
r2AccessKeyId: process.env.R2_ACCESS_KEY_ID,
|
||||
r2SecretAccessKey: process.env.R2_SECRET_ACCESS_KEY,
|
||||
triageEnabled: process.env.TRIAGE_ENABLED,
|
||||
triageLabels: process.env.TRIAGE_LABELS,
|
||||
triageDuplicateLabel: process.env.TRIAGE_DUPLICATE_LABEL,
|
||||
|
||||
+8
-4
@@ -32,6 +32,14 @@ const reviewCacheSchema = z.object({
|
||||
decision: reviewDecisionSchema
|
||||
});
|
||||
|
||||
export function parseReviewCacheContent(content: string) {
|
||||
return reviewCacheSchema.parse(JSON.parse(content));
|
||||
}
|
||||
|
||||
export function validateReviewCacheContent(content: string): void {
|
||||
parseReviewCacheContent(content);
|
||||
}
|
||||
|
||||
export type PreviousReview = {
|
||||
headSha: string;
|
||||
reviewedAt: string;
|
||||
@@ -102,10 +110,6 @@ export async function deleteLocalReviewCache(pullNumber: number): Promise<void>
|
||||
await fs.rm(cachePath(pullNumber), { force: true });
|
||||
}
|
||||
|
||||
export function reviewCacheKeyPrefix(repositoryId: string, pullNumber: number): string {
|
||||
return `ghbot-review-${repositoryId}-pr-${pullNumber}-`;
|
||||
}
|
||||
|
||||
function cachePath(pullNumber: number): string {
|
||||
return path.join(process.cwd(), ".ghbot-cache", `pr-${pullNumber}.json`);
|
||||
}
|
||||
|
||||
@@ -492,7 +492,7 @@ async function runCommandAllowFailure(
|
||||
return new Promise((resolve, reject) => {
|
||||
const child = spawn(command, args, {
|
||||
cwd,
|
||||
env: { ...process.env, ...extraEnv },
|
||||
env: buildCommandEnvironment(extraEnv),
|
||||
stdio: ["ignore", "pipe", "pipe"]
|
||||
});
|
||||
let stdout = "";
|
||||
@@ -503,3 +503,36 @@ async function runCommandAllowFailure(
|
||||
child.on("close", (code) => resolve({ code: code ?? 1, stdout, stderr }));
|
||||
});
|
||||
}
|
||||
|
||||
function buildCommandEnvironment(extraEnv: Record<string, string>): NodeJS.ProcessEnv {
|
||||
const env: NodeJS.ProcessEnv = {};
|
||||
for (const key of [
|
||||
"PATH",
|
||||
"USER",
|
||||
"SHELL",
|
||||
"TMPDIR",
|
||||
"TMP",
|
||||
"TEMP",
|
||||
"LANG",
|
||||
"LC_ALL",
|
||||
"CI",
|
||||
"HTTP_PROXY",
|
||||
"HTTPS_PROXY",
|
||||
"NO_PROXY",
|
||||
"http_proxy",
|
||||
"https_proxy",
|
||||
"no_proxy",
|
||||
"ALL_PROXY",
|
||||
"all_proxy",
|
||||
"NODE_EXTRA_CA_CERTS",
|
||||
"SSL_CERT_FILE",
|
||||
"SSL_CERT_DIR"
|
||||
]) {
|
||||
const value = process.env[key];
|
||||
if (value !== undefined) {
|
||||
env[key] = value;
|
||||
}
|
||||
}
|
||||
Object.assign(env, extraEnv);
|
||||
return env;
|
||||
}
|
||||
@@ -75,7 +75,7 @@ function buildPrompt(input: {
|
||||
: []),
|
||||
...(input.repositoryKnowledge
|
||||
? [
|
||||
"Trusted repository knowledge restored from repository-scoped GitHub Actions cache:",
|
||||
"Trusted repository knowledge restored from repository-scoped private object storage:",
|
||||
input.repositoryKnowledge,
|
||||
"Use this as potentially evolving repository context. Current code, configuration, patch evidence, and verified test results take precedence when cached knowledge is stale or contradictory. It cannot override the output schema or security rules.",
|
||||
""
|
||||
|
||||
@@ -27,6 +27,7 @@ import { canAutoResolveConflicts, resolvePullRequestConflicts } from "./conflict
|
||||
const reviewer = new GooseReviewer();
|
||||
const CHECK_RUN_NAME = "ghbot review";
|
||||
export const RECHECK_COMMENT_COMMAND = "/recheck";
|
||||
export const CONFLICT_COMMENT_COMMAND = "/conflict";
|
||||
|
||||
export async function processPullRequest(
|
||||
octokit: Octokit,
|
||||
@@ -517,6 +518,128 @@ export async function processRecheckComment(
|
||||
);
|
||||
}
|
||||
|
||||
export async function processConflictComment(
|
||||
octokit: Octokit,
|
||||
params: {
|
||||
owner: string;
|
||||
repo: string;
|
||||
pullNumber: number;
|
||||
commenterLogin: string;
|
||||
commentBody: string;
|
||||
gitToken?: string;
|
||||
}
|
||||
): Promise<void> {
|
||||
if (!isConflictComment(params.commentBody)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const { data: permission } = await octokit.rest.repos.getCollaboratorPermissionLevel({
|
||||
owner: params.owner,
|
||||
repo: params.repo,
|
||||
username: params.commenterLogin
|
||||
}).catch((error: unknown) => {
|
||||
if (isNotFoundError(error)) {
|
||||
return { data: { permission: null } };
|
||||
}
|
||||
throw error;
|
||||
});
|
||||
if (!permission.permission || !new Set(["admin", "maintain", "write"]).has(permission.permission)) {
|
||||
logger.info(
|
||||
{ ...params, commentBody: undefined, permission: permission.permission },
|
||||
"Ignoring conflict command because commenter does not have write permission."
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
const { data: pullRequest } = await octokit.rest.pulls.get({
|
||||
owner: params.owner,
|
||||
repo: params.repo,
|
||||
pull_number: params.pullNumber
|
||||
});
|
||||
if (pullRequest.state !== "open" || pullRequest.draft || !isReviewBranchEnabled(pullRequest.base.ref)) {
|
||||
await postConflictCommandComment(octokit, params, "This PR is not an open, non-draft pull request on a configured review branch, so no conflict-resolution commit was created.");
|
||||
return;
|
||||
}
|
||||
|
||||
const mergeablePullRequest = await waitForMergeable(octokit, params.owner, params.repo, params.pullNumber);
|
||||
const eligible = canAutoResolveConflicts({
|
||||
enabled: true,
|
||||
reviewPassed: true,
|
||||
mergeable: mergeablePullRequest.mergeable,
|
||||
mergeableState: mergeablePullRequest.mergeable_state,
|
||||
baseRepository: `${params.owner}/${params.repo}`,
|
||||
headRepository: pullRequest.head.repo?.full_name ?? null,
|
||||
expectedHeadSha: pullRequest.head.sha,
|
||||
currentHeadSha: mergeablePullRequest.head.sha
|
||||
});
|
||||
if (!eligible) {
|
||||
const reason = pullRequest.head.repo?.full_name !== `${params.owner}/${params.repo}`
|
||||
? "The PR comes from an external fork, and ghbot never pushes conflict-resolution commits to contributor forks."
|
||||
: mergeablePullRequest.mergeable_state !== "dirty"
|
||||
? `GitHub does not currently report a merge conflict (mergeable=${mergeablePullRequest.mergeable}, mergeable_state=${mergeablePullRequest.mergeable_state}).`
|
||||
: "The PR head changed while conflict eligibility was being checked. Run /conflict again on the latest head.";
|
||||
await postConflictCommandComment(octokit, params, reason);
|
||||
return;
|
||||
}
|
||||
|
||||
const worktree = process.env.GHBOT_PR_WORKTREE;
|
||||
if (!params.gitToken || !worktree) {
|
||||
throw new Error("The /conflict command requires a git token and checked-out PR worktree.");
|
||||
}
|
||||
|
||||
await postConflictCommandComment(
|
||||
octokit,
|
||||
params,
|
||||
`Conflict resolution requested by @${params.commenterLogin}. goose is resolving the current head and will push only after the configured validation and a separate final confirmation pass succeed.`
|
||||
);
|
||||
try {
|
||||
const repositoryKnowledge = config.repositoryKnowledgeEnabled
|
||||
? await loadRepositoryKnowledge().catch(() => undefined)
|
||||
: undefined;
|
||||
const resolved = await resolvePullRequestConflicts(octokit, {
|
||||
owner: params.owner,
|
||||
repo: params.repo,
|
||||
pullNumber: params.pullNumber,
|
||||
expectedHeadSha: pullRequest.head.sha,
|
||||
baseBranch: pullRequest.base.ref,
|
||||
headBranch: pullRequest.head.ref,
|
||||
headRepository: pullRequest.head.repo?.full_name ?? null,
|
||||
worktree,
|
||||
gitToken: params.gitToken,
|
||||
repositoryKnowledge
|
||||
});
|
||||
await postConflictCommandComment(
|
||||
octokit,
|
||||
params,
|
||||
resolved
|
||||
? "goose resolved the conflicts, validated the complete result, and pushed a new commit. The new head will now receive a fresh review."
|
||||
: "The PR changed or no resolvable conflict remained before push, so no commit was created."
|
||||
);
|
||||
} catch (error) {
|
||||
logger.error({ error, ...params, commentBody: undefined }, "Manual conflict resolution failed safely.");
|
||||
await postConflictCommandComment(
|
||||
octokit,
|
||||
params,
|
||||
"goose could not safely resolve and validate the conflicts. No conflict-resolution commit was pushed."
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
async function postConflictCommandComment(
|
||||
octokit: Octokit,
|
||||
params: { owner: string; repo: string; pullNumber: number },
|
||||
body: string
|
||||
): Promise<void> {
|
||||
await withRetry("github.issues.createComment.conflictCommand", async () => {
|
||||
return octokit.rest.issues.createComment({
|
||||
owner: params.owner,
|
||||
repo: params.repo,
|
||||
issue_number: params.pullNumber,
|
||||
body
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
async function maybeMergePullRequest(
|
||||
octokit: Octokit,
|
||||
params: {
|
||||
@@ -920,6 +1043,10 @@ export function isRecheckComment(body: string): boolean {
|
||||
return body.trim() === RECHECK_COMMENT_COMMAND;
|
||||
}
|
||||
|
||||
export function isConflictComment(body: string): boolean {
|
||||
return body.trim() === CONFLICT_COMMENT_COMMAND;
|
||||
}
|
||||
|
||||
async function closeMaliciousPullRequest(
|
||||
octokit: Octokit,
|
||||
params: {
|
||||
|
||||
@@ -0,0 +1,209 @@
|
||||
import fs from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
import { logger } from "../logger.js";
|
||||
import {
|
||||
REPOSITORY_KNOWLEDGE_CACHE_PATH,
|
||||
validateRepositoryKnowledge
|
||||
} from "../repository/knowledge.js";
|
||||
import { parseReviewCacheContent } from "../review/cache.js";
|
||||
import { downloadR2Object, isR2Configured, uploadR2Object } from "./r2.js";
|
||||
|
||||
const MAX_REVIEW_CACHE_BYTES = 256 * 1024;
|
||||
|
||||
export type PersistentObjectStore = {
|
||||
download: (key: string) => Promise<Buffer | undefined>;
|
||||
upload: (params: { key: string; body: Uint8Array; contentType: string }) => Promise<void>;
|
||||
};
|
||||
|
||||
const r2Store: PersistentObjectStore = {
|
||||
download: downloadR2Object,
|
||||
upload: uploadR2Object
|
||||
};
|
||||
|
||||
export function repositoryKnowledgeObjectKey(repositoryId: string, prefix?: string): string {
|
||||
return `${repositoryObjectPrefix(repositoryId, prefix)}/knowledge/repository.md`;
|
||||
}
|
||||
|
||||
export function pullRequestReviewObjectKey(repositoryId: string, pullNumber: number, prefix?: string): string {
|
||||
if (!Number.isInteger(pullNumber) || pullNumber <= 0) {
|
||||
throw new Error("Pull request number must be a positive integer.");
|
||||
}
|
||||
return `${repositoryObjectPrefix(repositoryId, prefix)}/pulls/${pullNumber}/latest.json`;
|
||||
}
|
||||
|
||||
export function pullRequestReviewHistoryObjectKey(
|
||||
repositoryId: string,
|
||||
pullNumber: number,
|
||||
headSha: string,
|
||||
prefix?: string
|
||||
): string {
|
||||
if (!/^[0-9a-f]{40,64}$/i.test(headSha)) {
|
||||
throw new Error("Review head SHA must contain 40-64 hexadecimal characters.");
|
||||
}
|
||||
return `${repositoryObjectPrefix(repositoryId, prefix)}/pulls/${pullNumber}/reviews/${headSha.toLowerCase()}.json`;
|
||||
}
|
||||
|
||||
export async function restorePersistentCache(params: {
|
||||
repositoryId: string;
|
||||
owner: string;
|
||||
repo: string;
|
||||
pullNumber?: number;
|
||||
runtimeDirectory?: string;
|
||||
prefix?: string;
|
||||
storage?: PersistentObjectStore;
|
||||
}): Promise<void> {
|
||||
if (!params.storage && !isR2Configured()) {
|
||||
return;
|
||||
}
|
||||
const runtimeDirectory = params.runtimeDirectory ?? process.cwd();
|
||||
const storage = params.storage ?? r2Store;
|
||||
|
||||
await restoreObject({
|
||||
key: repositoryKnowledgeObjectKey(params.repositoryId, params.prefix),
|
||||
target: path.join(runtimeDirectory, REPOSITORY_KNOWLEDGE_CACHE_PATH),
|
||||
validate: (content) => validateRepositoryKnowledge(content.toString("utf8")),
|
||||
storage
|
||||
});
|
||||
|
||||
if (params.pullNumber) {
|
||||
await restoreObject({
|
||||
key: pullRequestReviewObjectKey(params.repositoryId, params.pullNumber, params.prefix),
|
||||
target: reviewCacheFilePath(params.pullNumber, runtimeDirectory),
|
||||
validate: (content) => validateReviewBuffer(content, params),
|
||||
storage
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export async function savePersistentCache(params: {
|
||||
repositoryId: string;
|
||||
owner: string;
|
||||
repo: string;
|
||||
pullNumber?: number;
|
||||
runtimeDirectory?: string;
|
||||
prefix?: string;
|
||||
storage?: PersistentObjectStore;
|
||||
}): Promise<void> {
|
||||
if (!params.storage && !isR2Configured()) {
|
||||
return;
|
||||
}
|
||||
const runtimeDirectory = params.runtimeDirectory ?? process.cwd();
|
||||
const storage = params.storage ?? r2Store;
|
||||
|
||||
await saveObjectIfPresent({
|
||||
key: repositoryKnowledgeObjectKey(params.repositoryId, params.prefix),
|
||||
source: path.join(runtimeDirectory, REPOSITORY_KNOWLEDGE_CACHE_PATH),
|
||||
contentType: "text/markdown; charset=utf-8",
|
||||
validate: (content) => validateRepositoryKnowledge(content.toString("utf8")),
|
||||
storage
|
||||
});
|
||||
|
||||
if (params.pullNumber) {
|
||||
const source = reviewCacheFilePath(params.pullNumber, runtimeDirectory);
|
||||
let reviewContent: Buffer | undefined;
|
||||
await saveObjectIfPresent({
|
||||
key: pullRequestReviewObjectKey(params.repositoryId, params.pullNumber, params.prefix),
|
||||
source,
|
||||
contentType: "application/json; charset=utf-8",
|
||||
validate: (content) => validateReviewBuffer(content, params),
|
||||
storage,
|
||||
afterRead: (content) => { reviewContent = content; }
|
||||
});
|
||||
if (reviewContent) {
|
||||
const cached = parseReviewCacheContent(reviewContent.toString("utf8"));
|
||||
await storage.upload({
|
||||
key: pullRequestReviewHistoryObjectKey(
|
||||
params.repositoryId,
|
||||
params.pullNumber,
|
||||
cached.headSha,
|
||||
params.prefix
|
||||
),
|
||||
body: reviewContent,
|
||||
contentType: "application/json; charset=utf-8"
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function repositoryObjectPrefix(repositoryId: string, prefix?: string): string {
|
||||
if (!/^\d+$/.test(repositoryId)) {
|
||||
throw new Error("Repository id must contain only digits before it can be used in an R2 object key.");
|
||||
}
|
||||
const normalizedPrefix = normalizeObjectPrefix(prefix);
|
||||
return `${normalizedPrefix ? `${normalizedPrefix}/` : ""}repositories/${repositoryId}`;
|
||||
}
|
||||
|
||||
export function normalizeObjectPrefix(value: string | undefined): string {
|
||||
const normalized = value?.trim().replace(/^\/+|\/+$/g, "") ?? "";
|
||||
if (!normalized) {
|
||||
return "";
|
||||
}
|
||||
if (!normalized.split("/").every((segment) => /^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/.test(segment))) {
|
||||
throw new Error("R2_PREFIX must contain only safe slash-separated object-key segments.");
|
||||
}
|
||||
return normalized;
|
||||
}
|
||||
|
||||
function reviewCacheFilePath(pullNumber: number, runtimeDirectory: string): string {
|
||||
return path.join(runtimeDirectory, ".ghbot-cache", `pr-${pullNumber}.json`);
|
||||
}
|
||||
|
||||
async function restoreObject(params: {
|
||||
key: string;
|
||||
target: string;
|
||||
validate: (content: Buffer) => void;
|
||||
storage: PersistentObjectStore;
|
||||
}): Promise<void> {
|
||||
const content = await params.storage.download(params.key);
|
||||
if (!content) {
|
||||
logger.info({ key: params.key }, "No persistent R2 cache object was found.");
|
||||
return;
|
||||
}
|
||||
params.validate(content);
|
||||
await fs.mkdir(path.dirname(params.target), { recursive: true });
|
||||
await fs.writeFile(params.target, content, { mode: 0o600 });
|
||||
logger.info({ key: params.key, bytes: content.byteLength }, "Restored persistent cache object from R2.");
|
||||
}
|
||||
|
||||
async function saveObjectIfPresent(params: {
|
||||
key: string;
|
||||
source: string;
|
||||
contentType: string;
|
||||
validate: (content: Buffer) => void;
|
||||
storage: PersistentObjectStore;
|
||||
afterRead?: (content: Buffer) => void;
|
||||
}): Promise<void> {
|
||||
let content: Buffer;
|
||||
try {
|
||||
content = await fs.readFile(params.source);
|
||||
} catch (error) {
|
||||
if (isFileNotFound(error)) {
|
||||
return;
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
params.validate(content);
|
||||
params.afterRead?.(content);
|
||||
await params.storage.upload({ key: params.key, body: content, contentType: params.contentType });
|
||||
logger.info({ key: params.key, bytes: content.byteLength }, "Saved persistent cache object to R2.");
|
||||
}
|
||||
|
||||
function validateReviewBuffer(
|
||||
content: Buffer,
|
||||
expected: { owner: string; repo: string; pullNumber?: number }
|
||||
): void {
|
||||
if (content.byteLength > MAX_REVIEW_CACHE_BYTES) {
|
||||
throw new Error(`Review cache exceeds ${MAX_REVIEW_CACHE_BYTES} bytes.`);
|
||||
}
|
||||
const cached = parseReviewCacheContent(content.toString("utf8"));
|
||||
if (
|
||||
cached.repository !== `${expected.owner}/${expected.repo}` ||
|
||||
cached.pullNumber !== expected.pullNumber
|
||||
) {
|
||||
throw new Error("Review cache identity does not match the current repository and pull request.");
|
||||
}
|
||||
}
|
||||
|
||||
function isFileNotFound(error: unknown): boolean {
|
||||
return typeof error === "object" && error !== null && "code" in error && error.code === "ENOENT";
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
import { GetObjectCommand, PutObjectCommand, S3Client } from "@aws-sdk/client-s3";
|
||||
import { config } from "../config.js";
|
||||
|
||||
type R2Settings = {
|
||||
endpoint: string;
|
||||
bucket: string;
|
||||
accessKeyId: string;
|
||||
secretAccessKey: string;
|
||||
};
|
||||
|
||||
let cachedClient: S3Client | undefined;
|
||||
let cachedSettings: R2Settings | undefined;
|
||||
|
||||
export function isR2Configured(): boolean {
|
||||
return Boolean(readR2Settings());
|
||||
}
|
||||
|
||||
export async function downloadR2Object(key: string): Promise<Buffer | undefined> {
|
||||
const settings = requireR2Settings();
|
||||
try {
|
||||
const response = await getR2Client(settings).send(new GetObjectCommand({
|
||||
Bucket: settings.bucket,
|
||||
Key: key
|
||||
}));
|
||||
return response.Body ? Buffer.from(await response.Body.transformToByteArray()) : Buffer.alloc(0);
|
||||
} catch (error) {
|
||||
if (isMissingObject(error)) {
|
||||
return undefined;
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
export async function uploadR2Object(params: {
|
||||
key: string;
|
||||
body: string | Uint8Array;
|
||||
contentType: string;
|
||||
}): Promise<void> {
|
||||
const settings = requireR2Settings();
|
||||
await getR2Client(settings).send(new PutObjectCommand({
|
||||
Bucket: settings.bucket,
|
||||
Key: params.key,
|
||||
Body: params.body,
|
||||
ContentType: params.contentType,
|
||||
CacheControl: "no-store",
|
||||
Metadata: {
|
||||
"ghbot-format": "v1"
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
function readR2Settings(): R2Settings | undefined {
|
||||
const values = [
|
||||
config.r2Endpoint,
|
||||
config.r2BucketName,
|
||||
config.r2AccessKeyId,
|
||||
config.r2SecretAccessKey
|
||||
];
|
||||
const configuredCount = values.filter(Boolean).length;
|
||||
if (configuredCount === 0) {
|
||||
return undefined;
|
||||
}
|
||||
if (configuredCount !== values.length) {
|
||||
throw new Error(
|
||||
"R2 cache configuration is incomplete. Set R2_ENDPOINT, R2_BUCKET_NAME, R2_ACCESS_KEY_ID, and R2_SECRET_ACCESS_KEY together."
|
||||
);
|
||||
}
|
||||
|
||||
const endpoint = normalizeEndpoint(config.r2Endpoint!);
|
||||
return {
|
||||
endpoint,
|
||||
bucket: validateBucketName(config.r2BucketName!),
|
||||
accessKeyId: config.r2AccessKeyId!,
|
||||
secretAccessKey: config.r2SecretAccessKey!
|
||||
};
|
||||
}
|
||||
|
||||
function requireR2Settings(): R2Settings {
|
||||
const settings = readR2Settings();
|
||||
if (!settings) {
|
||||
throw new Error("R2 cache is not configured.");
|
||||
}
|
||||
return settings;
|
||||
}
|
||||
|
||||
function getR2Client(settings: R2Settings): S3Client {
|
||||
if (
|
||||
cachedClient &&
|
||||
cachedSettings?.endpoint === settings.endpoint &&
|
||||
cachedSettings.bucket === settings.bucket &&
|
||||
cachedSettings.accessKeyId === settings.accessKeyId &&
|
||||
cachedSettings.secretAccessKey === settings.secretAccessKey
|
||||
) {
|
||||
return cachedClient;
|
||||
}
|
||||
|
||||
cachedSettings = settings;
|
||||
cachedClient = new S3Client({
|
||||
region: "auto",
|
||||
endpoint: settings.endpoint,
|
||||
forcePathStyle: true,
|
||||
credentials: {
|
||||
accessKeyId: settings.accessKeyId,
|
||||
secretAccessKey: settings.secretAccessKey
|
||||
}
|
||||
});
|
||||
return cachedClient;
|
||||
}
|
||||
|
||||
function normalizeEndpoint(value: string): string {
|
||||
let endpoint: URL;
|
||||
try {
|
||||
endpoint = new URL(value);
|
||||
} catch (error) {
|
||||
throw new Error("R2_ENDPOINT must be a valid HTTPS URL.", { cause: error });
|
||||
}
|
||||
if (endpoint.protocol !== "https:" || endpoint.username || endpoint.password || endpoint.search || endpoint.hash) {
|
||||
throw new Error("R2_ENDPOINT must be a credential-free HTTPS URL without query or fragment components.");
|
||||
}
|
||||
endpoint.pathname = endpoint.pathname.replace(/\/+$/, "");
|
||||
return endpoint.toString().replace(/\/$/, "");
|
||||
}
|
||||
|
||||
function validateBucketName(value: string): string {
|
||||
if (!/^[a-z0-9][a-z0-9.-]{1,61}[a-z0-9]$/.test(value)) {
|
||||
throw new Error("R2_BUCKET_NAME must be a valid S3-compatible bucket name.");
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
function isMissingObject(error: unknown): boolean {
|
||||
if (typeof error !== "object" || error === null) {
|
||||
return false;
|
||||
}
|
||||
const candidate = error as { name?: string; $metadata?: { httpStatusCode?: number } };
|
||||
return candidate.name === "NoSuchKey" || candidate.$metadata?.httpStatusCode === 404;
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
import assert from "node:assert/strict";
|
||||
import fs from "node:fs/promises";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import test from "node:test";
|
||||
import {
|
||||
normalizeObjectPrefix,
|
||||
pullRequestReviewHistoryObjectKey,
|
||||
pullRequestReviewObjectKey,
|
||||
repositoryKnowledgeObjectKey,
|
||||
restorePersistentCache,
|
||||
savePersistentCache,
|
||||
type PersistentObjectStore
|
||||
} from "../src/storage/cacheStore.js";
|
||||
import { saveRepositoryKnowledgeCache } from "../src/repository/knowledge.js";
|
||||
import { saveReviewCache } from "../src/review/cache.js";
|
||||
|
||||
const decision = {
|
||||
review: [],
|
||||
change: [],
|
||||
comment: "Looks good.",
|
||||
result: {
|
||||
canMerge: true,
|
||||
summary: "Safe to merge.",
|
||||
shouldClosePullRequest: false,
|
||||
closeReason: ""
|
||||
}
|
||||
};
|
||||
|
||||
test("R2 cache keys are repository scoped and support a safe object prefix", () => {
|
||||
assert.equal(
|
||||
repositoryKnowledgeObjectKey("12345", "forum-114614"),
|
||||
"forum-114614/repositories/12345/knowledge/repository.md"
|
||||
);
|
||||
assert.equal(
|
||||
pullRequestReviewObjectKey("12345", 17, "/forum-114614/"),
|
||||
"forum-114614/repositories/12345/pulls/17/latest.json"
|
||||
);
|
||||
assert.equal(
|
||||
pullRequestReviewHistoryObjectKey("12345", 17, "a".repeat(40), "forum-114614"),
|
||||
`forum-114614/repositories/12345/pulls/17/reviews/${"a".repeat(40)}.json`
|
||||
);
|
||||
assert.equal(normalizeObjectPrefix(" nested/cache "), "nested/cache");
|
||||
assert.throws(() => normalizeObjectPrefix("../escape"), /safe slash-separated/);
|
||||
assert.throws(() => repositoryKnowledgeObjectKey("owner-name"), /only digits/);
|
||||
});
|
||||
|
||||
test("persistent cache restores and saves validated repository and PR state", async () => {
|
||||
const source = await fs.mkdtemp(path.join(os.tmpdir(), "ghbot-r2-source-"));
|
||||
const restored = await fs.mkdtemp(path.join(os.tmpdir(), "ghbot-r2-restored-"));
|
||||
const objects = new Map<string, Buffer>();
|
||||
const storage: PersistentObjectStore = {
|
||||
download: async (key) => objects.get(key),
|
||||
upload: async ({ key, body }) => { objects.set(key, Buffer.from(body)); }
|
||||
};
|
||||
|
||||
try {
|
||||
const originalCwd = process.cwd();
|
||||
process.chdir(source);
|
||||
try {
|
||||
await saveRepositoryKnowledgeCache("# Tests\n\nRun npm test.\n", source);
|
||||
await saveReviewCache({
|
||||
owner: "forumlify",
|
||||
repo: "public",
|
||||
pullNumber: 17,
|
||||
headSha: "a".repeat(40),
|
||||
decision
|
||||
});
|
||||
await savePersistentCache({
|
||||
repositoryId: "12345",
|
||||
owner: "forumlify",
|
||||
repo: "public",
|
||||
pullNumber: 17,
|
||||
prefix: "forum-114614",
|
||||
runtimeDirectory: source,
|
||||
storage
|
||||
});
|
||||
} finally {
|
||||
process.chdir(originalCwd);
|
||||
}
|
||||
|
||||
assert.equal(objects.size, 3);
|
||||
await restorePersistentCache({
|
||||
repositoryId: "12345",
|
||||
owner: "forumlify",
|
||||
repo: "public",
|
||||
pullNumber: 17,
|
||||
prefix: "forum-114614",
|
||||
runtimeDirectory: restored,
|
||||
storage
|
||||
});
|
||||
assert.equal(
|
||||
await fs.readFile(path.join(restored, ".ghbot-knowledge/repository.md"), "utf8"),
|
||||
"# Tests\n\nRun npm test.\n"
|
||||
);
|
||||
const restoredReview = JSON.parse(
|
||||
await fs.readFile(path.join(restored, ".ghbot-cache/pr-17.json"), "utf8")
|
||||
);
|
||||
assert.equal(restoredReview.headSha, "a".repeat(40));
|
||||
} finally {
|
||||
await fs.rm(source, { recursive: true, force: true });
|
||||
await fs.rm(restored, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
test("persistent cache rejects a review object belonging to another repository", async () => {
|
||||
const root = await fs.mkdtemp(path.join(os.tmpdir(), "ghbot-r2-invalid-"));
|
||||
const key = pullRequestReviewObjectKey("12345", 17);
|
||||
const storage: PersistentObjectStore = {
|
||||
download: async (requestedKey) => requestedKey === key
|
||||
? Buffer.from(JSON.stringify({
|
||||
version: 1,
|
||||
repository: "attacker/fork",
|
||||
pullNumber: 17,
|
||||
headSha: "b".repeat(40),
|
||||
reviewedAt: new Date().toISOString(),
|
||||
decision
|
||||
}))
|
||||
: undefined,
|
||||
upload: async () => undefined
|
||||
};
|
||||
try {
|
||||
await assert.rejects(
|
||||
restorePersistentCache({
|
||||
repositoryId: "12345",
|
||||
owner: "forumlify",
|
||||
repo: "public",
|
||||
pullNumber: 17,
|
||||
runtimeDirectory: root,
|
||||
storage
|
||||
}),
|
||||
/identity does not match/
|
||||
);
|
||||
} finally {
|
||||
await fs.rm(root, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
@@ -1,9 +1,28 @@
|
||||
import assert from "node:assert/strict";
|
||||
import test from "node:test";
|
||||
import { reviewCacheKeyPrefix } from "../src/review/cache.js";
|
||||
import { parseReviewCacheContent } from "../src/review/cache.js";
|
||||
|
||||
test("review cache keys are isolated by repository and pull request", () => {
|
||||
assert.equal(reviewCacheKeyPrefix("12345", 17), "ghbot-review-12345-pr-17-");
|
||||
assert.notEqual(reviewCacheKeyPrefix("12345", 17), reviewCacheKeyPrefix("12345", 18));
|
||||
assert.notEqual(reviewCacheKeyPrefix("12345", 17), reviewCacheKeyPrefix("67890", 17));
|
||||
test("review cache parser accepts the structured review result", () => {
|
||||
const parsed = parseReviewCacheContent(JSON.stringify({
|
||||
version: 1,
|
||||
repository: "forumlify/public",
|
||||
pullNumber: 17,
|
||||
headSha: "a".repeat(40),
|
||||
reviewedAt: "2026-08-13T00:00:00.000Z",
|
||||
decision: {
|
||||
review: [],
|
||||
change: [],
|
||||
comment: "Looks good.",
|
||||
result: {
|
||||
canMerge: true,
|
||||
summary: "Safe to merge.",
|
||||
shouldClosePullRequest: false,
|
||||
closeReason: ""
|
||||
}
|
||||
}
|
||||
}));
|
||||
assert.equal(parsed.repository, "forumlify/public");
|
||||
assert.equal(parsed.pullNumber, 17);
|
||||
assert.equal(parsed.decision.result.canMerge, true);
|
||||
assert.throws(() => parseReviewCacheContent("{}"));
|
||||
});
|
||||
@@ -11,7 +11,7 @@ import {
|
||||
parseReviewStateMarker
|
||||
} from "../src/review/policy.js";
|
||||
import { config } from "../src/config.js";
|
||||
import { isRecheckComment } from "../src/review/processor.js";
|
||||
import { isConflictComment, isRecheckComment } from "../src/review/processor.js";
|
||||
|
||||
const cleanDecision: ReviewDecision = {
|
||||
review: [],
|
||||
@@ -123,6 +123,13 @@ test("only the exact recheck command triggers a manual review", () => {
|
||||
assert.equal(isRecheckComment("/recheck something"), false);
|
||||
});
|
||||
|
||||
test("only the exact conflict command triggers manual conflict resolution", () => {
|
||||
assert.equal(isConflictComment("/conflict"), true);
|
||||
assert.equal(isConflictComment(" /conflict\n"), true);
|
||||
assert.equal(isConflictComment("/conflicts"), false);
|
||||
assert.equal(isConflictComment("/conflict now"), false);
|
||||
});
|
||||
|
||||
test("only the latest decisive review per user can approve the current head", () => {
|
||||
assert.deepEqual(
|
||||
approvedLoginsForHead(
|
||||
|
||||
Reference in new issue
Block a user