From 823dd3fd61f74ed8fcc030fb6c70352d9c670304 Mon Sep 17 00:00:00 2001 From: He Wang Date: Thu, 16 Jul 2026 20:26:26 +0800 Subject: [PATCH 1/3] fix(review): align self-review image and attribution fix: - Build the OpenCode review image from the exact pull request head - Attribute review comments to the bot and show the active skill fingerprint test: - Remove presentation-only assertions from repository tests docs: - Document the development-image self-review workflow --- .github/workflows/code-review.yml | 11 ++++++- AGENTS.md | 16 +++++----- docker/README.md | 16 +++++----- .../review/publish/formatter.py | 6 +++- tests/test_opencode_image.py | 30 +------------------ tests/test_review_publisher.py | 29 ++---------------- 6 files changed, 35 insertions(+), 73 deletions(-) diff --git a/.github/workflows/code-review.yml b/.github/workflows/code-review.yml index e01697c..aaa0a69 100644 --- a/.github/workflows/code-review.yml +++ b/.github/workflows/code-review.yml @@ -27,6 +27,15 @@ jobs: runs-on: ubuntu-latest timeout-minutes: 60 steps: + - name: Check out pull request source + uses: actions/checkout@v4 + with: + ref: ${{ github.event.pull_request.head.sha }} + persist-credentials: false + + - name: Build review image + run: docker build --target opencode --tag code-review-bot:pr-head . + - name: Run code review env: AUTO_APPROVE_ON_CLEAN_REVIEW: "true" @@ -60,5 +69,5 @@ jobs: -e OPENCODE_UPSTREAM_ENDPOINT \ -e OPENCODE_UPSTREAM_API_KEY \ -e OPENCODE_MODEL \ - whhe/code-review-bot:opencode \ + code-review-bot:pr-head \ --cr-id "${{ github.event.pull_request.number }}" diff --git a/AGENTS.md b/AGENTS.md index d0296b7..a03385c 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -149,13 +149,15 @@ credential helper so tokens are never embedded in workspace URLs or Git metadata factory explicitly forwards only the required OpenCode runtime environment through ACP's filtered subprocess environment. Existing global config files are left untouched. -`.github/workflows/code-review.yml` runs `whhe/code-review-bot:opencode` for non-draft, -same-repository pull requests targeting `main` and skips fork pull requests. Dependabot pull -requests are allowed to run, but GitHub does not provide Actions secrets and grants the built-in -`GITHUB_TOKEN` read-only permissions for those runs. The workflow therefore prefers an optional -`CODE_REVIEW_GITHUB_TOKEN` secret and falls back to the built-in token; Dependabot reviews require -same-named Dependabot secrets for that write-capable token and `OPENCODE_UPSTREAM_API_KEY`. The -workflow uses repository variables for `OPENCODE_UPSTREAM_ENDPOINT` and `OPENCODE_MODEL`. +`.github/workflows/code-review.yml` checks out the exact pull-request head, builds the shared +Dockerfile's OpenCode target locally, and runs that development image for non-draft, +same-repository pull requests targeting `main`; fork pull requests are skipped. Checkout does not +persist credentials into the build context. Dependabot pull requests are allowed to run, but GitHub +does not provide Actions secrets and grants the built-in `GITHUB_TOKEN` read-only permissions for +those runs. The workflow therefore prefers an optional `CODE_REVIEW_GITHUB_TOKEN` secret and falls +back to the built-in token; Dependabot reviews require same-named Dependabot secrets for that +write-capable token and `OPENCODE_UPSTREAM_API_KEY`. The workflow uses repository variables for +`OPENCODE_UPSTREAM_ENDPOINT` and `OPENCODE_MODEL`. It enables clean-review approval with `AUTO_APPROVE_ON_CLEAN_REVIEW=true` and debug logging with `LOG_LEVEL=DEBUG`; the repository must allow GitHub Actions to create and approve pull requests for the built-in token to approve a clean review. diff --git a/docker/README.md b/docker/README.md index aaa5846..40aa096 100644 --- a/docker/README.md +++ b/docker/README.md @@ -176,7 +176,8 @@ Optionally set `ANTHROPIC_MODEL`. ### GitHub Actions The repository includes `.github/workflows/code-review.yml`, which reviews pull requests targeting -`main` with `whhe/code-review-bot:opencode`. Configure these values under **Settings → Secrets and +`main`. It checks out the exact pull-request head, builds the shared Dockerfile's `opencode` target +locally, and runs that development image. Configure these values under **Settings → Secrets and variables → Actions** before enabling the workflow: | Type | Name | Description | @@ -190,14 +191,13 @@ Actions → General → Workflow permissions**, enable **Allow GitHub Actions to pull requests** so clean reviews can be approved with the built-in `GITHUB_TOKEN`. The workflow runs for opened, updated, reopened, and ready-for-review pull requests. It uses the -built-in `GITHUB_TOKEN` with `contents: read` and `pull-requests: write`. The workflow itself does -not check out or directly execute the pull-request branch, and it skips draft and fork pull +built-in `GITHUB_TOKEN` with `contents: read` and `pull-requests: write`. It checks out and executes +the pull-request branch without persisting checkout credentials, and it skips draft and fork pull requests. Fork pull requests are skipped because GitHub does not expose repository secrets to -their `pull_request` workflows; branches inside the repository should therefore be limited to -trusted collaborators. Dependabot pull requests are not skipped, but GitHub supplies Dependabot -secrets instead of Actions secrets and gives the built-in `GITHUB_TOKEN` read-only permissions for -those runs. To review them, add these values under **Settings → Secrets and variables → -Dependabot**: +their `pull_request` workflows; branches inside the repository must therefore be limited to trusted +collaborators. Dependabot pull requests are not skipped, but GitHub supplies Dependabot secrets +instead of Actions secrets and gives the built-in `GITHUB_TOKEN` read-only permissions for those +runs. To review them, add these values under **Settings → Secrets and variables → Dependabot**: | Name | Description | |---|---| diff --git a/src/code_review_bot/review/publish/formatter.py b/src/code_review_bot/review/publish/formatter.py index 405fb63..00ea59b 100644 --- a/src/code_review_bot/review/publish/formatter.py +++ b/src/code_review_bot/review/publish/formatter.py @@ -6,6 +6,7 @@ from code_review_bot.skill.protocol import Finding, count_findings_by_severity BOT_METADATA_PREFIX = "