Add pr-reviewer module: Gitea webhooks, Spring AI structured output, quote-checked inline comments, de-duplication across pushes and live tests against Gitea 1.27.3 on Spring AI 2.1.0
Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_017ic4b4HkWoC7hLzk61vZa8
This commit is contained in:
Executable
+41
@@ -0,0 +1,41 @@
|
||||
#!/usr/bin/env bash
|
||||
# The packaged application, a local Gitea and a local model, wired the way a deployment is.
|
||||
# Needs: scripts/gitea-up.sh and scripts/ollama-up.sh already run, and LLM_URL / LLM_MODEL exported. Writes output/20.
|
||||
set -euo pipefail
|
||||
cd "$(dirname "$0")/.."
|
||||
. scripts/.gitea.env
|
||||
(cd .. && mvn -B -q -pl pr-reviewer -am package -DskipTests)
|
||||
API=http://127.0.0.1:3118/api/v1
|
||||
as() { local t=$1; shift; curl -s --noproxy '*' -H "Authorization: token $t" -H 'Content-Type: application/json' "$@"; }
|
||||
REPO=demo-$RANDOM
|
||||
SECRET=local-$RANDOM$RANDOM
|
||||
GITEA_URL=http://127.0.0.1:3118 GITEA_TOKEN=$GITEA_BOT_TOKEN GITEA_WEBHOOK_SECRET=$SECRET \
|
||||
OPENAI_BASE_URL=$LLM_URL OPENAI_MODEL=$LLM_MODEL \
|
||||
java -jar target/pr-reviewer-1.0.0.jar --server.port=8118 --spring.ai.openai.timeout=600s > target/app.log 2>&1 &
|
||||
APP=$!
|
||||
trap 'kill $APP 2>/dev/null || true' EXIT
|
||||
until grep -q 'Started ReviewerApplication' target/app.log; do sleep 1; kill -0 $APP; done
|
||||
as $GITEA_DEV_TOKEN -d "{\"name\":\"$REPO\",\"auto_init\":true,\"default_branch\":\"main\"}" $API/user/repos >/dev/null
|
||||
as $GITEA_DEV_TOKEN -X PUT -d '{"permission":"write"}' $API/repos/dev/$REPO/collaborators/reviewbot
|
||||
as $GITEA_DEV_TOKEN -d "{\"type\":\"gitea\",\"active\":true,\"events\":[\"pull_request\"],\"config\":{\"url\":\"http://$WEBHOOK_HOST:8118/webhook/gitea\",\"content_type\":\"json\",\"secret\":\"$SECRET\"}}" $API/repos/dev/$REPO/hooks >/dev/null
|
||||
CODE=$(printf 'package shop;\n\npublic class Greeter {\n}\n' | base64 -w0)
|
||||
as $GITEA_DEV_TOKEN -d "{\"content\":\"$CODE\",\"message\":\"base\",\"branch\":\"main\"}" $API/repos/dev/$REPO/contents/src/Greeter.java >/dev/null
|
||||
SHA=$(as $GITEA_DEV_TOKEN $API/repos/dev/$REPO/contents/src/Greeter.java | grep -o '"sha":"[0-9a-f]*"' | head -1 | cut -d'"' -f4)
|
||||
CODE=$(printf 'package shop;\n\npublic class Greeter {\n String password = "hunter2";\n\n boolean isAdmin(String role) {\n return role == "admin";\n }\n}\n' | base64 -w0)
|
||||
START=$(date +%s)
|
||||
as $GITEA_DEV_TOKEN -X PUT -d "{\"content\":\"$CODE\",\"sha\":\"$SHA\",\"message\":\"feature\",\"branch\":\"main\",\"new_branch\":\"feature\"}" $API/repos/dev/$REPO/contents/src/Greeter.java >/dev/null
|
||||
as $GITEA_DEV_TOKEN -d '{"head":"feature","base":"main","title":"Greeter"}' $API/repos/dev/$REPO/pulls >/dev/null
|
||||
for i in $(seq 1 600); do grep -qE 'reviewed dev/|review of .* failed' target/app.log && break; sleep 1; done
|
||||
END=$(date +%s)
|
||||
{
|
||||
echo "packaged jar, local Gitea 1.27.3, model $LLM_MODEL on a 2 vCPU CPU, one pull request"
|
||||
echo "seconds from opening the pull request to the finished report: $((END - START))"
|
||||
grep -E 'reviewed dev/|review of .* failed' target/app.log | sed 's/^.* : //' | sed 's/, /,\n /g'
|
||||
echo
|
||||
echo "inline comments read back from Gitea:"
|
||||
for id in $(as $GITEA_DEV_TOKEN $API/repos/dev/$REPO/pulls/1/reviews | python3 -I -c 'import json,sys; print(*[r["id"] for r in json.load(sys.stdin)])'); do
|
||||
as $GITEA_DEV_TOKEN $API/repos/dev/$REPO/pulls/1/reviews/$id/comments | python3 -I -c 'import json,sys
|
||||
for c in json.load(sys.stdin): print(" %s:%d\n%s" % (c["path"], c["position"], "\n".join(" "+l for l in c["body"].splitlines())))'
|
||||
done
|
||||
} > output/20-live-demo.txt
|
||||
cat output/20-live-demo.txt
|
||||
Reference in New Issue
Block a user