Repository navigation
feat: PR review bot with scanner/fixer pattern - #10
Conversation
Signed-off-by: Gloire Rubambiza <[email protected]>
Signed-off-by: Gloire Rubambiza <[email protected]>
Signed-off-by: Gloire Rubambiza <[email protected]>
Signed-off-by: Gloire Rubambiza <[email protected]>
Signed-off-by: Gloire Rubambiza <[email protected]>
Signed-off-by: Gloire Rubambiza <[email protected]>
Signed-off-by: Gloire Rubambiza <[email protected]>
The bot posts reviews via the PR review API, but the skip logic was checking issue comments. This caused duplicate reviews every cycle. Signed-off-by: Gloire Rubambiza <[email protected]>
Rename pr-review-bot.sh to pr-review-scanner.sh with full rewrite: state management, eviction pass, reports output, dry-run support. Update standing order to document the new architecture. Assisted-By: Claude Opus 4.6 <[email protected]> Signed-off-by: Gloire Rubambiza <[email protected]>
- iso_to_epoch: GNU date -> BSD date -> pure awk fallback (no python3) - atomic_write_file: temp file + mv to avoid argument-length limits - validate_json_schema: structural check with auto-reset on corruption Assisted-By: Claude Opus 4.6 <[email protected]> Signed-off-by: Gloire Rubambiza <[email protected]>
Converts unified diffs to structured JSON with absolute line numbers and LEFT/RIGHT side markers. Used by the fixer to give the agent deterministic line numbers for PR review inline comments. Assisted-By: Claude Opus 4.6 <[email protected]> Signed-off-by: Gloire Rubambiza <[email protected]>
Two modes: begin (marks PRs in_progress, fetches diff, outputs enriched queue with diff_map) and finalize (confirms reviews via API, moves to reviewed state). Safe-by-default: requires --live to write state. Assisted-By: Claude Opus 4.6 <[email protected]> Signed-off-by: Gloire Rubambiza <[email protected]>
- test-parse-diff-map.sh: 30 assertions for diff parser correctness - test-pr-review-integration.sh: 28 assertions validating the full scanner -> fixer begin -> fixer finalize pipeline against live PRs Assisted-By: Claude Opus 4.6 <[email protected]> Signed-off-by: Gloire Rubambiza <[email protected]>
mrsabath
left a comment
There was a problem hiding this comment.
Summary
Genuinely well-built shell — set -euo pipefail throughout, atomic temp-file writes, temp-file iteration to dodge subshell scoping, schema validation with safe reset, a portable iso_to_epoch with a pure-awk fallback, and good test coverage (escaping, multi-hunk, multi-file, stdin all handled correctly — I verified). Security posture is sound: no PR-controlled data reaches a shell eval, repo/marker values are internal constants, the SHA marker grep is anchored to [a-f0-9]+, and it's read-only by design.
One blocker, in parse-diff-map.sh: the parser mishandles deleted files. The destination header for a delete is +++ /dev/null, which the /^\+\+\+ b\// rule doesn't match — so no {"path":...,"hunks":[ object is opened, yet the @@/content lines still emit hunk JSON. For a lone deleted file you get an object with no path; in a multi-file diff the output is invalid JSON (...]}{"lines":... — missing comma). The fixer pipes this straight into jq, so a single deleted file breaks the entire diff_map and the bot can't review that PR. Deleted files are common, so this will fire in practice. The existing tests don't cover deleted files or renames, which is why CI is green.
Reproduced locally:
# mixed diff: normal file followed by a deleted file →
[{"path":"keep.txt",...]}{"lines":[...]}] # jq: parse error
Approving once deleted files parse correctly (and ideally a test covers them). The suggestion + nit are non-blocking.
Areas reviewed: Shell, Security, Tests, Docs, Commits
Author: rubambiza (MEMBER — maintainer)
Commits: 13, all signed-off (DCO ✓)
CI: DCO passing
Nice architecture overall — the scanner/fixer split and the deterministic diff_map (keeping hunk arithmetic out of the LLM) are the right call.
| } | ||
|
|
||
| # File path from the +++ line (destination side) | ||
| /^\+\+\+ b\// { |
There was a problem hiding this comment.
suggestion — Same root cause, lesser impact: a pure rename (rename from/rename to, no hunk, no +++ b/) yields [] for that file, so the bot silently won't comment on renamed files. If renamed-with-changes diffs do carry a +++ b/ header they're fine; pure renames don't. Worth handling alongside the delete fix, or at least noting the limitation.
There was a problem hiding this comment.
Verified: pure renames (similarity index 100%, no hunks) produce [] — valid JSON, and since there are no changed lines, there is nothing for the bot to comment on. Renames with content changes already work correctly because they carry a +++ b/new-name line. I think the current behavior is correct for both cases — no additional handling needed.
The parser only matched `+++ b/...` for file paths, missing deleted files whose destination is `+++ /dev/null`. This caused malformed JSON when a diff contained deleted files, breaking the fixer's diff_map for that PR entirely. Fix: capture the source path from `--- a/...` and use it when `+++ /dev/null` is encountered. Also add \f and \b escaping for additional JSON control characters. Adds 15 new test assertions covering standalone deleted files and multi-file diffs with deleted files interleaved. Assisted-By: Claude Opus 4.6 <[email protected]> Signed-off-by: Gloire Rubambiza <[email protected]>
There was a problem hiding this comment.
Summary
The must-fix is properly resolved. c76a037 adds a +++ /dev/null handler that opens the file object using the source path captured from the --- a/... line, so deleted files now parse correctly — and it ships with regression tests (Test 7: standalone deleted file; Test 8: multi-file diff containing a delete, including a valid-JSON assertion). Exactly the fix-plus-coverage I'd hoped for.
Verified locally against the cases that broke before:
- Deleted file →
{"path":"gone.txt", removed:[1,2]}(was: missingpath) - Normal + deleted in one diff → valid JSON
["keep.txt","gone.txt"](was: invalid JSON,jqparse error) - No regressions: no-newline marker, special-char escaping, and a removed
---line all still parse correctly.
Approving. The two non-blocking items from the prior review remain optional follow-ups, not gating:
- Pure renames (
rename from/rename to, no hunk) still yield[]for that file — the bot won't comment on a pure rename. Fine to leave; worth a note or a later issue. - Control-char escaping covers
\ " \t \rbut not\f/raw control bytes — bulletproofing only, rare in source diffs.
Areas reviewed: Shell, Security, Tests, Docs, Commits
Author: rubambiza (MEMBER — maintainer)
Commits: 14, all signed-off (DCO ✓)
CI: DCO passing
Nice turnaround — fix + targeted tests is the right way to close a parser bug. The bot's in good shape to start reviewing.
Summary
ready-for-ai-review, manages state (eviction, dedup), writes reports--liveto write state; scanner supports--dry-runTest plan
bash tests/test-parse-diff-map.sh— 30 unit assertions for diff parserbash tests/test-pr-review-integration.sh --repo kagenti/kagenti --pr 1881— 28 integration assertionsFixes rossoctl/rossoctl#1910