Files

code-review-bot

Companion code for Build an AI Code-Review Bot in Java (Gitea/GitHub Webhook + Spring AI) on ankurm.com. A webhook receiver that checks Gitea's HMAC signature, a diff chunker that numbers lines of the new file, a Spring AI ChatClient that reviews each chunk, and a posting step that keeps only comments that can be attached to a line. No API key: the tests use ScriptedChatModel, a scripted ChatModel.

mvn test -pl code-review-bot      # rewrites output/*.txt
File Role
WebhookController Verifies X-Gitea-Signature over the raw body, filters events, queues the review and answers 202
Hmac Bare lowercase hex HMAC-SHA256 with a constant-time comparison
DiffChunker Unified diff to chunks: file boundaries respected, new-file line numbers, lockfiles and binaries skipped
ReviewService The prompt, the content-keyed cache, the chunk cap, the severity filter, the "is this an added line?" guard
GitHost, GiteaHost The two calls the bot needs; the Gitea endpoints were checked against Gitea 1.27.3's swagger. GiteaHost is not exercised against a live server by the tests

Not covered here: running it against a real model, GitHub's payload (the X-Hub-Signature-256 header carries a sha256= prefix), and review threading on later pushes.

Verified with Spring Boot 4.1.1, Spring AI spring-ai-client-chat 2.0.1, JDK 25, JUnit 6.1.3.