Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/codewhale-review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ name: Codewhale PR Review
# line comments, anchored to the PR head SHA. CODEOWNERS (@Hmbown) stays the
# human owner — this review posts alongside it and never approves.
#
# Setup:
# Setup — full step-by-step guide in docs/GITHUB_APP.md. Summary:
# 1. Provider key: Settings -> Secrets and variables -> Actions ->
# New repository secret `DEEPSEEK_API_KEY` (or the env var matching a
# different provider, see crates/secrets `env_for`).
Expand Down
89 changes: 89 additions & 0 deletions docs/GITHUB_APP.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# GitHub App Setup (Codewhale Agent reviews)

`codewhale review --pr N` writes an advisory code review of a pull request. With
`--post` (or from CI) the review is published to GitHub. Published reviews can
appear under two identities:

- the default token the CI job already has (`github.token`), or
- a dedicated **GitHub App** so the review shows as a bot — e.g.
`codewhale-agent[bot]` — instead of a personal account.

The App identity is optional. Nothing below is needed to run
`codewhale review --pr N` locally and print the report to your terminal.

Related docs:

- [Automatic Workflows](AUTOMATIC_WORKFLOWS.md) — the review workflow in context
- [Providers](PROVIDERS.md) — the model/key used to write the review
- [Receipts](RECEIPTS.md) — how posted reviews are anchored to a head SHA

## One-time setup, five steps

You need owner access to the GitHub repository once. After these five steps
every non-draft pull request gets a Codewhale review posted as the App.

1. **Create the App.** GitHub → *Settings → Developer settings → GitHub Apps →
New GitHub App*. Name it (e.g. `Codewhale Agent`), set a homepage URL, and
**uncheck Webhook → Active** — the review is pulled on PR events by Actions,
so no webhook is needed.
2. **Grant two repository permissions.**
- *Pull requests* → **Read & write** (to post the review and inline comments)
- *Contents* → **Read-only** (to read the diff; read-only is enough — avoid
write unless you have another reason)
Comment on lines +31 to +32

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Remove unnecessary Contents access from the App

When this App is installed on a private repository, granting Contents: Read-only exposes the entire repository even though the App token is not used for checkout—the workflow mints it only after actions/checkout at .github/workflows/codewhale-review.yml:46-58—and the CLI uses it only for gh pr view, gh pr diff`, repository metadata, and posting a pull-request review. Pull-request read/write plus the metadata permission implicit for GitHub Apps covers those operations, so remove this permission rather than expanding the impact of an App-key compromise.

Useful? React with 👍 / 👎.

Choose *Only on this account*, then **Create GitHub App**.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Cover organization-owned repositories in the App setup

When the target repository belongs to an organization but the App was created from the user's personal Developer settings as this sequence suggests, selecting Only on this account restricts installation to that personal account, so the organization repository cannot be selected in step 4 even if the user administers it. Distinguish personal and organization ownership here: create an organization-owned App from the organization's settings, or allow installation on other accounts and have the organization approve it.

Useful? React with 👍 / 👎.

3. **Download the private key.** On the App's page, *Private keys → Generate a
private key*. Keep the `.pem` file secret; it is the App's credential.
4. **Install the App** on your account (*Install App* on the same page) and
select the repositories reviews should cover.
5. **Add three repository settings.** GitHub → *Settings → Secrets and
variables → Actions*:

| Kind | Name | Value |
|----------|--------------------------|----------------------------------------|
| Variable | `CODEWHALE_APP_ID` | the App ID shown on the App's page |
| Secret | `CODEWHALE_APP_PRIVATE_KEY` | the full `.pem` file contents |
| Secret | `DEEPSEEK_API_KEY` | provider key for the review model (or the env var matching your provider; see [Providers](PROVIDERS.md)) |

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Restrict setup instructions to the provider secret actually read

When a user follows the parenthetical for another provider—for example, by creating OPENROUTER_API_KEY instead—the documented workflow still checks only secrets.DEEPSEEK_API_KEY in .github/workflows/codewhale-review.yml:36 and exports only that secret at line 76, so it exits through the green skip step and never reviews anything. Either document this workflow as DeepSeek-only or update its key detection and environment mapping before directing users to substitute another provider's variable.

AGENTS.md reference: AGENTS.md:L32-L32

Useful? React with 👍 / 👎.


`DEEPSEEK_API_KEY` is the only required one. Until it exists, the workflow
skips itself with a green notice — it is safe to merge the workflow before
finishing setup. Optional: variable `CODEWHALE_REVIEW_MODEL` overrides the
model (e.g. `deepseek-chat`).

## How the pieces connect

`.github/workflows/codewhale-review.yml` runs on every non-draft PR. When

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Limit the claim to pull requests covered by the workflow

This says the workflow runs on every non-draft PR, but .github/workflows/codewhale-review.yml:21-24 only handles the listed activity types for PRs targeting master or main. For example, an already-open PR present when setup is completed receives no review until another triggering activity occurs, and a PR targeting a release branch never runs this job; qualify this statement and the similar promise at line 23 with the actual trigger scope.

AGENTS.md reference: AGENTS.md:L3-L5

Useful? React with 👍 / 👎.

`CODEWHALE_APP_ID` **and** `CODEWHALE_APP_PRIVATE_KEY` are both present, the
job mints a short-lived installation token for the App
(`actions/create-github-app-token`) and hands it to the CLI as `GH_TOKEN`.
Otherwise it falls back to the workflow's own `github.token`. The CLI never
stores the token; each run mints a fresh one.

The review itself is one **COMMENT** review — a summary body plus inline line
comments anchored to the PR head SHA. It never approves or requests changes;
CODEOWNERS stays the human authority.

## Running a review yourself

```sh
# print a report locally (uses your configured provider key)
codewhale review --pr 1234
Comment on lines +68 to +69

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Document the GitHub CLI prerequisite for local reviews

When a user follows this local example without gh installed and authenticated, the command fails before generating a report: run_review explicitly rejects a missing GitHub CLI at crates/tui/src/lib.rs:8172-8177, and both PR metadata and the diff are fetched through gh. Add gh installation and authentication (or a usable GH_TOKEN) to this section rather than stating only that a configured provider key is needed.

Useful? React with 👍 / 👎.


# publish it to GitHub as whichever identity GH_TOKEN carries
codewhale review --pr 1234 --post
```

`GH_TOKEN` may be your `gh` CLI token (posts as you) or an App installation
token (posts as the App). The `--post` flag is always opt-in.

## Troubleshooting

- **Review posts as you, not the bot.** The variable or the private-key secret
is missing/empty; the job silently falls back to `github.token`. Check both
names character-for-character.
- **Workflow logs "DEEPSEEK_API_KEY is not set — skipping".** Expected until
the provider secret exists.
- **App token step fails.** The `.pem` was regenerated after the secret was
set — paste the newest key into `CODEWHALE_APP_PRIVATE_KEY` again, and
confirm the App is actually installed on the repository.
- **Name already taken.** GitHub App names are global; pick another name. The
bot's display login is `<slug>[bot]`, derived from the name.
3 changes: 3 additions & 0 deletions docs/GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,9 @@ kept in the provider registry document.

Soft-auto multi-agent work: [AUTOMATIC_WORKFLOWS.md](AUTOMATIC_WORKFLOWS.md).

Posting Codewhale PR reviews as a bot identity:
[GITHUB_APP.md](GITHUB_APP.md).

Next for durable multi-worker work: [FLEET_WORKFLOW_TUTORIAL.md](FLEET_WORKFLOW_TUTORIAL.md)
walks through Fleet task specs, monitoring, and Workflow authoring.

Expand Down
Loading