tests / unittest (push) Successful in 19s
Callers use Civilytics/docs-review/.gitea/workflows/review.yml@v1 with secrets: inherit. Stage 1 on every pull request; for drafter: claude, a 180-second wait and then the sandboxed drafter; closed pull requests close their docs PR; schedule and dispatch run the monthly pass. Tested live against Gitea 28.3 (drafter none, a misspelled drafter, claude, close). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
139 lines
6.2 KiB
Markdown
139 lines
6.2 KiB
Markdown
# docs-review
|
|
|
|
`docs_review` keeps living documents current. On each Gitea pull request it flags
|
|
the documents the change makes stale. If the repository opts in, it also has Claude
|
|
Code draft the edits. It is a Python package with no dependencies outside the standard
|
|
library.
|
|
|
|
## What it does
|
|
|
|
Stage 1 compares the pull request's changes with the documents you list. It uses no model
|
|
and sends nothing anywhere. With `drafter: none` it posts one comment with the flags it
|
|
finds, and edits that comment on later runs:
|
|
|
|
- **touched**: a listed document mentions a file or function the change modified.
|
|
- **dead**: a listed document refers to a path the change removed or renamed.
|
|
- **uncovered**: a new source file that no listed document mentions.
|
|
- **stale generated**: a generated document that mentions an input the change
|
|
modified, where the change did not regenerate it.
|
|
- **unguided**: a listed document that the doc guide does not describe.
|
|
|
|
Stage 2 runs only with `drafter: claude`. Claude Code reads the change, the flags and the
|
|
listed documents, and decides which documents need edits; the flags are hints, not a
|
|
limit. The edits go into a second pull request into the feature branch, for the author to
|
|
review and merge. Later runs add commits to that pull request rather than replacing it.
|
|
|
|
The monthly pass runs on a schedule. It treats every file as new and reports the
|
|
uncovered and unguided flags for the whole repository in one issue. With
|
|
`drafter: claude` it opens a pull request with proposed edits instead.
|
|
|
|
## What it never does
|
|
|
|
- It never pushes to the pull request's branch.
|
|
- It never force-pushes.
|
|
- It never merges anything.
|
|
- It posts nothing when nothing is flagged.
|
|
|
|
For a pull request from a branch of the same repository, Gitea runs the caller workflow
|
|
from the pull request's head, so anyone who can push a branch can change the caller's
|
|
inputs. The safeguards in this README bound what the pull request's content can do, not
|
|
what an edited caller workflow file can do.
|
|
|
|
## What is sent to Anthropic
|
|
|
|
Nothing is sent unless the repository sets `drafter: claude`. With it, the drafter
|
|
receives the diff (or a list of changed files), the listed documents, the repository's
|
|
`CLAUDE.md` and the doc guide.
|
|
|
|
Claude runs with file tools only (read, search, edit), with no shell, and its permission
|
|
rules confine those tools to its working directory. That directory is a copy of the tree
|
|
with no `.git` and no symlinks, and only listed documents are copied back out of it.
|
|
Its environment is an allowlist: system basics and its own Claude credential. The Gitea
|
|
token never reaches it, drafted files are checked for credential values before they are
|
|
committed, and everything posted to Gitea has credential values replaced with `***`.
|
|
|
|
## Install
|
|
|
|
Add a workflow to the repository you want reviewed, at `.gitea/workflows/docs-review.yml`:
|
|
|
|
```yaml
|
|
name: docs-review
|
|
on:
|
|
pull_request:
|
|
branches: [main]
|
|
types: [opened, synchronize, reopened, closed]
|
|
schedule:
|
|
- cron: "0 9 1 * *" # the monthly pass, on the first of the month
|
|
workflow_dispatch:
|
|
concurrency:
|
|
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
|
|
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
|
|
jobs:
|
|
docs:
|
|
uses: Civilytics/docs-review/.gitea/workflows/review.yml@v1
|
|
with:
|
|
tool_ref: v1
|
|
drafter: none
|
|
docs: |
|
|
README.md
|
|
docs/*.md
|
|
doc_guide: docs/README.md
|
|
secrets: inherit
|
|
```
|
|
|
|
- `closed` in the pull request types lets the workflow close a docs pull request whose
|
|
feature pull request merged or closed first.
|
|
- The `concurrency` block cancels a run when the pull request is pushed again. With
|
|
`drafter: claude` the workflow waits three minutes between stage 1 and drafting, so a
|
|
quick re-push cancels a run before it has spent anything.
|
|
- `tool_ref` must name the same version as the `@` in `uses:`. Gitea does not tell a
|
|
called workflow which ref it was called at, so the workflow fetches the tool's code at
|
|
`tool_ref`.
|
|
- A `workflow_dispatch` run is the monthly pass for the current month.
|
|
|
|
The job runs in the `node:22` image. It clones the repository with the bot token, so
|
|
it needs no checkout action, and it installs Claude Code
|
|
(`@anthropic-ai/claude-code`, a pinned version) only when `drafter` is `claude` and a
|
|
Claude credential is set. With `drafter: claude` and no credential, it posts the stage 1
|
|
comment with a note saying so and fails. The drafter's cost and turn count are printed
|
|
in the log and appended to `$GITHUB_STEP_SUMMARY`.
|
|
|
|
The package can also be run by hand: `python3 -m docs_review pr|closed|monthly --help`.
|
|
|
|
## Inputs
|
|
|
|
| Input | Default | Meaning |
|
|
|---|---|---|
|
|
| `drafter` | `none` | `none` flags only. `claude` also drafts edits. `local` is accepted but not yet built: it fails the job with "local drafter not built yet". Any other value, including a misspelling, behaves as `none`. |
|
|
| `docs` | required | Newline-separated patterns for the living documents. |
|
|
| `generated` | none | Patterns for generated files. |
|
|
| `top_level` | `README.md` | The subset of `docs` the monthly pass re-reads in full. |
|
|
| `source_dirs` | `R` and `scripts` | Newline-separated directories whose files count as source. |
|
|
| `workstream` | `docs` | Scope in draft commit messages, as `docs(<workstream>): ...`. |
|
|
| `tracking_issue` | none | Issue number the monthly pass's commit messages cite. |
|
|
| `doc_guide` | none | Path to the document that says who reads each listed document and what it is for. The drafter writes for that reader. |
|
|
| `model` | `claude-sonnet-5-5` | Model used when `drafter` is `claude`. |
|
|
| `tool_ref` | `v1` | The docs-review branch or tag to run; the same as the `@` in `uses:`. |
|
|
|
|
## Secrets
|
|
|
|
- `DOCS_REVIEW_BOT_TOKEN` is required. It is a token for a Gitea bot account with
|
|
write access to the repository and the token scopes `write:repository`,
|
|
`write:issue` and `read:user`. An organization secret serves every repository in the
|
|
organization.
|
|
- `CLAUDE_CODE_OAUTH_TOKEN` or `ANTHROPIC_API_KEY` is needed only for
|
|
`drafter: claude`.
|
|
|
|
## Tests
|
|
|
|
```
|
|
python3 -m unittest discover -s tests -v
|
|
```
|
|
|
|
The tests use only the standard library and a fake `claude` executable. They need
|
|
Python 3.11 or later and make no network calls.
|
|
|
|
## License
|
|
|
|
MIT. See `LICENSE`.
|