Repository navigation
fix(ci): skip automated Claude review for trivial/docs-only PRs - #2117
Conversation
automated-review ran an unconditional, deliberately expensive Claude review (root-cause analysis, backlog compliance grading, etc.) on every human- authored PR — 271 in the last 30 days, no size or scope gating. Unlike the GitHub Actions compute discussed elsewhere in this cost-reduction effort, this is real, non-discounted Anthropic API spend. Add a detect-trivial-pr job that skips the review for docs-only diffs and single-file diffs under 5 changed lines, while failing open (still reviewing) if the detector itself fails or is inconclusive — a broken detector can't silently wave through a substantive PR.
| TOTAL_CHANGED=$(git diff --numstat "$BASE_SHA" HEAD | awk '{a+=$1; d+=$2} END {print a+d+0}') | ||
| if [ "$NUM_FILES" -le 1 ] && [ "${TOTAL_CHANGED:-0}" -le 5 ]; then |
There was a problem hiding this comment.
Binary files silently count as 0 lines
git diff --numstat outputs -\t-\t<path> for binary files. AWK treats - as a string, which evaluates to 0 in arithmetic, so a PR that adds or replaces a single binary file (e.g. a compiled artifact, a test fixture image, a lock file in binary format) gets TOTAL_CHANGED=0, passes the NUM_FILES <= 1 && TOTAL_CHANGED <= 5 guard, and is marked trivial — skipping the review entirely. Adding --text would treat binaries as text lines and give a real count, but the cleaner fix is to explicitly detect binary entries in the --numstat output and force TOTAL_CHANGED to a high sentinel value when any are present.
There was a problem hiding this comment.
Fixed — git diff --numstat now runs through an awk pass that explicitly checks for the - sentinel in the added/deleted fields. If either field is - (binary file), TOTAL_CHANGED is forced to 999999, well above the trivial threshold, so a binary-only single-file change can no longer be miscounted as 0 lines and waved through as trivial. Verified locally against a normal text diff, a binary-only diff, a mixed binary+text diff, and an empty diff.
git diff --numstat prints "-\t-\t<path>" for binary files, which awk silently coerces to 0 in arithmetic. A single-file binary-only change was therefore counted as 0 lines and could pass the trivial guard, skipping the automated review. Detect the "-" sentinel explicitly and force TOTAL_CHANGED to a value above the threshold when any binary entry is present.
|
Addressed Greptile's review feedback:
|
Summary
Why
Part of the broader CI/CD cost-reduction effort (#2108), but distinct from the rest: this is the one confirmed non-discounted cost in that effort. Everything else in this effort is GitHub Actions compute, which is free for this public repo (100% discounted on the actual bill) — this job calls the Anthropic API directly (`anthropic_api_key: secrets.ANTHROPIC_API_KEY`) and that spend is real regardless of repo visibility.
Closes #2112
Test plan