| 1 | # GitHub review bot |
| 2 | |
| 3 | > 阅读简体中文版:[zh_hans/GITHUB_ACTION.md](zh_hans/GITHUB_ACTION.md) |
| 4 | |
| 5 | The root `action.yml` runs the existing `codewhale review` command with an |
| 6 | exact, checksummed release. It needs Node.js 22+, `gh`, Git, and a macOS or |
| 7 | Linux runner. It fetches Git objects without checking out or executing PR code. |
| 8 | The Engine owns review coverage, prompts, routing and finding generation. |
| 9 | |
| 10 | Use two jobs: analysis with a read-only GitHub token and the selected provider |
| 11 | key, followed by publication with a write token and no provider key. Analysis |
| 12 | exports a validated findings artifact. The publisher validates its repository, |
| 13 | PR, workflow run and attempt, and current base/head before submitting a |
| 14 | `COMMENT` review. It never approves, requests changes, commits, or runs a model. |
| 15 | |
| 16 | Automatic reviews and `@codewhale review` comments use the same review path. |
| 17 | The bot posts an advisory summary and validated inline findings. It never |
| 18 | approves or requests changes. Coding tasks that push a branch or open a PR |
| 19 | remain part of the hosted agent; this Action handles code review. |
| 20 | |
| 21 | ## Set up your own bot |
| 22 | |
| 23 | You need a GitHub repository with Actions enabled and one model API key. |
| 24 | No server or GitHub App is required. |
| 25 | |
| 26 | ### Turnkey CLI setup (`codewhale review init`) |
| 27 | |
| 28 | From the root of your repository, generate `.github/workflows/codewhale-review.yml` |
| 29 | directly with the Codewhale CLI: |
| 30 | |
| 31 | ```sh |
| 32 | codewhale review init --provider deepseek --model deepseek-chat --with-guidelines |
| 33 | ``` |
| 34 | |
| 35 | - Preserves the two-job split: a read-only `review` job (`pull-requests: read`, |
| 36 | `post: 'false'`) with the selected provider key, and a key-free `publish` job |
| 37 | (`pull-requests: write`) that posts advisory `COMMENT`-only reviews and never |
| 38 | auto-approves or requests changes. |
| 39 | - `--with-guidelines` also creates a `.codewhale/REVIEW.md` template for |
| 40 | repository-specific review focus areas. |
| 41 | - `--print` prints the generated YAML (and guidelines when combined with |
| 42 | `--with-guidelines`) to stdout without writing files. |
| 43 | - Refuses to overwrite existing files. |
| 44 | |
| 45 | ### Generator script from a source checkout |
| 46 | |
| 47 | Node.js 22+ and Git are needed only to run the standalone generator script from a |
| 48 | source checkout; GitHub's Ubuntu runner provides the review tools. |
| 49 | |
| 50 | 1. From a clean Codewhale source checkout, generate a workflow in your project: |
| 51 | |
| 52 | ```sh |
| 53 | node /path/to/Codewhale/scripts/github-action/setup.mjs \ |
| 54 | --directory /path/to/your-project \ |
| 55 | --provider deepseek --model deepseek-flash |
| 56 | ``` |
| 57 | |
| 58 | Select your own provider and exact model ID. The generator pins both |
| 59 | Codewhale actions to the source checkout's full commit and pins the CLI to a |
| 60 | specific released tag (override with `--version vX.Y.Z`), with a 16384-token |
| 61 | output allowance for the completed review. |
| 62 | It refuses to overwrite an existing workflow. Use `--print` to |
| 63 | inspect the YAML, `--version vX.Y.Z` to choose another released CLI, or |
| 64 | `--action-ref FULL_COMMIT_SHA` with a separately downloaded `setup.mjs`. |
| 65 | `--max-output-tokens N` changes the explicit output allowance. Reasoning |
| 66 | models can exhaust smaller automatic allowances before writing findings. |
| 67 | Generated workflows use `reasoning-effort: off` by default because smaller |
| 68 | internal token caps on older releases can be consumed |
| 69 | entirely by hidden reasoning. `--reasoning-effort auto` restores the |
| 70 | Engine default; other explicit effort levels are also available. The Action |
| 71 | writes only this non-secret setting into its isolated run configuration. |
| 72 | Increasing the Action allowance does not override a released CLI's smaller |
| 73 | internal cap. A completed review is still required before publication. |
| 74 | The generated workflow is `.github/workflows/codewhale-review.yml`. |
| 75 | |
| 76 | 2. Store only the selected provider's API key as a repository Actions secret: |
| 77 | |
| 78 | ```sh |
| 79 | gh secret set DEEPSEEK_API_KEY --repo OWNER/REPO |
| 80 | ``` |
| 81 | |
| 82 | This command prompts for the key. DeepSeek is the example; the provider |
| 83 | table below lists the other supported secrets. Never put a key in YAML. |
| 84 | |
| 85 | 3. Commit the workflow to your repository's default branch and push it. |
| 86 | Same-repository PRs are reviewed automatically when opened or updated. |
| 87 | For any open, non-draft PR, a maintainer can add exactly this comment, |
| 88 | or choose **Actions → Codewhale PR Review → Run workflow** |
| 89 | and enter its number: |
| 90 | |
| 91 | ```text |
| 92 | @codewhale review |
| 93 | ``` |
| 94 | |
| 95 | The generated workflow uses `github-actions[bot]`. To use your own existing |
| 96 | App, add `--app-login 'YOUR-APP[bot]'` when generating, set the |
| 97 | `CODEWHALE_APP_ID` variable and `CODEWHALE_APP_PRIVATE_KEY` secret, and install |
| 98 | the App on the repository. App workflows verify installation access in a |
| 99 | separate job before making a model request. The publisher requests only contents read and pull |
| 100 | requests write. A missing App configuration fails; it does not switch identity. |
| 101 | See [GitHub App setup](GITHUB_APP.md) for creating a new App. |
| 102 | |
| 103 | `--trigger-phrase @my-bot` changes the mention to `@my-bot review`. A mention |
| 104 | is an exact standalone comment; quoted text, arbitrary instructions, issue-only |
| 105 | comments, edited comments and bot authors do not trigger inference. New PR |
| 106 | review comments also work for same-repository PRs. Both the original actor |
| 107 | and an actor rerunning the workflow must still have write, maintain or admin |
| 108 | access when GitHub is queried. Association labels alone grant no access. |
| 109 | A deleted, edited or mismatched triggering comment is rejected. |
| 110 | |
| 111 | Fork PRs do not receive automatic model reviews. The generated workflow opts |
| 112 | into reviewing their inert diffs only through an authorized issue comment or |
| 113 | manual run from the default branch. It reads pinned Git objects without |
| 114 | checking out PR files, reading project configuration or executing candidate |
| 115 | code. The provider key belongs to that trusted job; no fork workflow receives |
| 116 | it. Leave `allow-forks: false` on both actions to disable this opt-in. |
| 117 | |
| 118 | The Action ref and exact CLI release are separate pins. Existing release tags |
| 119 | contain the original review action; mention support and the generator require |
| 120 | a commit containing these features. A moving major tag is not published by |
| 121 | this setup. Source installation does not prove a live provider review. |
| 122 | |
| 123 | ## Account configuration |
| 124 | |
| 125 | Codewhale-hosted GitHub reviews use the provider and model configured in the |
| 126 | Codewhale account, with any explicit saved repository override. OrcaRouter is |
| 127 | an optional provider connection, not a review default. Missing usable account |
| 128 | configuration requires setup; it does not select another provider. |
| 129 | |
| 130 | This standalone Action has explicit provider/model inputs and no default |
| 131 | provider. It does not fetch the hosted GitHub App settings automatically. Use |
| 132 | your own provider key, shown next; the account machine-key route is described |
| 133 | below. |
| 134 | |
| 135 | ## Use your own provider key |
| 136 | |
| 137 | Choose a provider and exact model, then pass only its key to the analysis job: |
| 138 | |
| 139 | | Provider | Actions secret | |
| 140 | | --- | --- | |
| 141 | | `deepseek` | `DEEPSEEK_API_KEY` | |
| 142 | | `anthropic` | `ANTHROPIC_API_KEY` | |
| 143 | | `openrouter` | `OPENROUTER_API_KEY` | |
| 144 | | `orcarouter` | `ORCAROUTER_API_KEY` | |
| 145 | | `zai` | `ZAI_API_KEY` | |
| 146 | | `modelstudio-token-plan` | `MODELSTUDIO_API_KEY` | |
| 147 | | `codewhale` | `CODEWHALE_API_KEY`, with a separately verified account machine-key route | |
| 148 | |
| 149 | The Action never switches credentials after an authentication, rate-limit or |
| 150 | payment failure. OrcaRouter is optional; its advertised free route still needs |
| 151 | a key and has provider limits. GitHub runner usage has its own cost and limits. |
| 152 | |
| 153 | The [workflow generator](../scripts/github-action/setup.mjs) is the complete |
| 154 | copy-ready example. It uses two ephemeral jobs, immutable action references, |
| 155 | read permissions for analysis, and write permission only for publication. |
| 156 | Neither job checks out repository code. The publishing job must use trusted |
| 157 | Action code and must not run files from the findings artifact. Do not combine |
| 158 | these jobs on a persistent runner: a later step on the analysis runner is not |
| 159 | a credential boundary. The publisher accepts only the current workflow run |
| 160 | and attempt; cross-workflow `workflow_run` publication is not implemented. |
| 161 | Never use `pull_request_target` with these actions. |
| 162 | |
| 163 | ### Account machine keys |
| 164 | |
| 165 | The `codewhale` provider uses `CODEWHALE_API_KEY` and an exact `provider/model` |
| 166 | account-catalog entry. Account sign-up availability does not establish that |
| 167 | machine-key relay access is qualified for Actions. Use explicit BYOK unless |
| 168 | your account's machine-key route has been separately verified. The Action runs |
| 169 | `codewhale account agent` before using that route. |
| 170 | |
| 171 | ## Bounds and evidence |
| 172 | |
| 173 | | Analysis input | Default | Meaning | |
| 174 | | --- | --- | --- | |
| 175 | | `version` | Required | Exact released CLI tag, never `latest` | |
| 176 | | `provider` | Required | Explicit BYOK provider, or `codewhale` for a verified account machine key | |
| 177 | | `model` | Required | Exact model ID; account mode uses `provider/model` | |
| 178 | | `reasoning-effort` | Engine automatic | Optional explicit reasoning level; generated workflows default to `off` | |
| 179 | | `max-chars` | 200000 | Complete diff characters per pass, maximum 8388608 | |
| 180 | | `max-passes` | 1 | Complete ordered passes, maximum 64 | |
| 181 | | `max-output-tokens` | CLI automatic | Optional per-pass ceiling, 8192–1000000 | |
| 182 | | `timeout-seconds` | 600 | Model/publication deadline, 30–1200 | |
| 183 | | `post` | `true` | Legacy direct publication; generated workflows use `false` | |
| 184 | | `trigger-phrase` | `@codewhale` | Exact mention name, followed by a standalone `review` command | |
| 185 | | `allow-forks` | `false` | Maintainer-triggered inert fork analysis from the default branch; set the same value on the publisher | |
| 186 | |
| 187 | These bounds do not guarantee a dollar cost. Model prices and reasoning |
| 188 | accounting vary. Raising the pass count authorizes more model requests. |
| 189 | Inference is never automatically retried. Set the intended review scope and |
| 190 | provider spend controls before enabling a workflow. |
| 191 | |
| 192 | Analysis outputs are `outcome`, `receipt`, `findings`, and `pr-url`. The |
| 193 | sanitized receipt records revision, route, bounds, completion counts, |
| 194 | publication state, and reported token usage. It excludes raw model/provider |
| 195 | output, PR text and credentials. Missing token accounting stays missing. |
| 196 | A runner shutdown before receipt creation is not a completed review. |
| 197 | |
| 198 | `findings` is populated only for complete `post:false` reviews. It contains |
| 199 | validated structured review text, evidence, file locations and exact revision |
| 200 | and workflow identity. Unknown fields, raw model output, provider errors and |
| 201 | replacement code are excluded; known supplied credentials are redacted. It |
| 202 | can still contain private source excerpts or other repository-sensitive text. |
| 203 | Store it only with the repository's intended artifact access and retention. |
| 204 | |
| 205 | The publisher reads the complete current PR file list and existing reviews, |
| 206 | then rechecks the base/head. It anchors inline findings only where GitHub |
| 207 | supplies a complete valid patch containing their line and the Engine records |
| 208 | introduced authorship. A finding needs a `reproduced` or `traced` evidence tier |
| 209 | with nonempty detail to appear in the review. Missing, empty and suspected |
| 210 | evidence stays in the analysis artifact; the review reports only the withheld |
| 211 | count. This checks the evidence record, not the truth of the claim. |
| 212 | Pre-existing findings appear in a collapsed section; unanchorable findings |
| 213 | and findings without recorded authorship appear in the body. Up to 50 |
| 214 | eligible findings are also posted inline; every retained finding stays in the |
| 215 | summary. Oversized review bodies fail before any write instead of silently |
| 216 | dropping findings. |
| 217 | |
| 218 | Freeform model summaries, merge-risk assessments and unlinked suggestions |
| 219 | stay in the analysis artifact so they cannot repeat a withheld allegation. |
| 220 | The published summary links to analysis and coverage and never treats an |
| 221 | empty finding list as approval. Publication receipts count evidence-eligible |
| 222 | `findings` and report `withheld_findings` separately. These rules apply to the |
| 223 | separate publisher; legacy `post:true` uses the pinned CLI's policy. |
| 224 | |
| 225 | The publisher recognizes its own review/finding fingerprints only on reviews |
| 226 | by `reviewer-login`. Identical review reruns are skipped. Findings with matching |
| 227 | normalized title/description, severity, location and unchanged file content are not repeated, |
| 228 | including after unrelated files change. Changed file contents can produce a |
| 229 | fresh finding. This is deterministic deduplication, not semantic similarity |
| 230 | judgment; differently worded findings can still recur. Concurrency must remain |
| 231 | serialized per PR because GitHub does not offer an atomic idempotency key for |
| 232 | review creation. |
| 233 | |
| 234 | The CLI validates complete diff coverage. It reads bounded excerpts from |
| 235 | pinned Git blobs; it does not execute PR tests or inspect arbitrary unchanged |
| 236 | callers. “Reviewed clean” means zero issues were reported in a completed |
| 237 | review, not proof that the PR contains no bugs. |
| 238 | |
| 239 | ## Outcomes and recovery |
| 240 | |
| 241 | | Outcome | Meaning / next action | |
| 242 | | --- | --- | |
| 243 | | `reviewed_clean` | Complete analysis with zero reported issues | |
| 244 | | `reviewed_with_findings` | Complete analysis; findings remain advisory | |
| 245 | | `published` | Publisher confirmed a `COMMENT` review at the captured head | |
| 246 | | `already_published` | Matching review or findings already exist under the configured publisher | |
| 247 | | `configuration_missing` | Check release/model, keys, bounds, artifact and workflow identity | |
| 248 | | `failed` | No complete analysis/publication receipt; inspect the safe reason code | |
| 249 | | `incomplete` | Coverage incomplete; revise scope or limits | |
| 250 | | `publication_uncertain` | Check the PR before retrying; the write may have succeeded | |
| 251 | | `superseded` | Base or head changed; analyze the current revision | |
| 252 | | `not_eligible` | Unapproved fork, draft, closed PR, unsupported event, stale comment or missing write access; no model run/write | |
| 253 | |
| 254 | Failures fail the optional job; whether it is a required merge check is the |
| 255 | repository owner's policy. A provider failure is not a negative verdict about |
| 256 | the PR. No additional failure comment is posted. |
| 257 | |
| 258 | After repairing setup, run the entire workflow with a PR number. Rerunning |
| 259 | only publication in a new run attempt rejects the old artifact; this prevents |
| 260 | silently publishing a bundle from another execution. Enabling a disabled |
| 261 | workflow does not replay old events. Legacy `post:true` preserves the CLI's |
| 262 | direct publication behavior and does not receive the separate publisher's |
| 263 | cross-run deduplication or write-token isolation. |
| 264 |