Skip to content

feat: PR review bot with scanner/fixer pattern - #10

Merged
rubambiza merged 14 commits into
rossoctl:mainfrom
rubambiza:feat/pr-review-bot
Jun 16, 2026
Merged

rubambiza merged 14 commits into
rossoctl:mainfrom
rubambiza:feat/pr-review-bot

Conversation

@rubambiza

@rubambiza rubambiza commented Jun 13, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Implements the PR review automation using the scanner/fixer pattern (third instance after link-health and dep-bump)
  • Scanner discovers PRs labeled ready-for-ai-review, manages state (eviction, dedup), writes reports
  • Fixer enriches the queue with a structured diff_map (deterministic line numbers for inline comments), manages state transitions between in_progress and reviewed
  • Standalone diff parser converts unified diffs to JSON with absolute line numbers and LEFT/RIGHT side markers
  • Safe-by-default: fixer requires --live to write state; scanner supports --dry-run
  • Portable: works on both macOS (BSD) and Linux (GNU) without python3

Test plan

  • bash tests/test-parse-diff-map.sh — 30 unit assertions for diff parser
  • bash tests/test-pr-review-integration.sh --repo kagenti/kagenti --pr 1881 — 28 integration assertions
  • Both test suites pass on the remote host (kagenti-bot)
  • Deploy to remote host and verify cron job fires correctly

Fixes rossoctl/rossoctl#1910

rubambiza added 13 commits June 12, 2026 11:48
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 mrsabath left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

Comment thread scripts/parse-diff-map.sh Resolved
Comment thread scripts/parse-diff-map.sh
}

# File path from the +++ line (destination side)
/^\+\+\+ b\// {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

Comment thread scripts/parse-diff-map.sh Resolved
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]>

@mrsabath mrsabath left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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: missing path)
  • Normal + deleted in one diff → valid JSON ["keep.txt","gone.txt"] (was: invalid JSON, jq parse 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 \r but 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.

@rubambiza
rubambiza merged commit a61699a into rossoctl:main Jun 16, 2026
1 check passed
@rubambiza
rubambiza deleted the feat/pr-review-bot branch June 16, 2026 12:21
@rubambiza rubambiza self-assigned this Jul 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: Automated PR review bot (clawgenti)

2 participants