#!/usr/bin/env bash # Usage: tools/dry-run [-h] [config] [--llm] # # Reviews a real Gitea PR without writing to Gitea (--no-publish), also a merged or closed one. # Without --llm it applies the deterministic rules only (--no-llm) and needs no OpenRouter key. # With --llm it calls the model and costs money. # Needs GITEA_BOT_TOKEN (read access is enough) and, with --llm, OPENROUTER_API_KEY in the environment; # with --llm and an [engine] mode other than "llm" also TYPESAFE_API_KEY. # The default config is config/hsadmin-ng.toml; a set WERKREVISOR_CONFIG_TOML wins over it. # Usage lines are appended to build/werkrevisor/usage.jsonl for later measurement. # # Example: # tools/dry-run https://git.example.org/owner/repo/pulls/302 set -euo pipefail if [[ $# -lt 1 || "$1" =~ ^(-h|-\?|--help)$ ]]; then awk 'NR > 1 && /^#/ { sub(/^# ?/, ""); print; next } NR > 1 { exit }' "$0" exit 0 fi image="pragent/pr-agent@sha256:7d98954c29289846a08faf00aaea0f1f1375b1676cd8a2ed303e0af07010af7a" pr_url="$1" config="${2:-config/hsadmin-ng.toml}" : "${GITEA_BOT_TOKEN:?GITEA_BOT_TOKEN must be set}" # Secrets are passed by name, so their values never appear in the process list. docker_env=(-e GITEA_BOT_TOKEN) # An inline operator config wins over the config file argument, as in production. [[ -n "${WERKREVISOR_CONFIG_TOML:-}" ]] && docker_env+=(-e WERKREVISOR_CONFIG_TOML) werkrevisor_args=(--no-llm) if [[ "${3:-}" == "--llm" ]]; then : "${OPENROUTER_API_KEY:?OPENROUTER_API_KEY must be set for --llm}" docker_env+=(-e OPENROUTER_API_KEY) [[ -n "${TYPESAFE_API_KEY:-}" ]] && docker_env+=(-e TYPESAFE_API_KEY) werkrevisor_args=() fi mkdir -p build/werkrevisor docker run --rm \ -v "$PWD":/werkrevisor:ro -v "$PWD/build":/work/build -w /work \ -e PYTHONPATH=/werkrevisor:/app -e PYTHONDONTWRITEBYTECODE=1 -e PYTHONNOUSERSITE=1 \ "${docker_env[@]}" \ --entrypoint python "$image" \ -s -m werkrevisor --config "/werkrevisor/$config" --pr-url "$pr_url" --no-publish --allow-closed "${werkrevisor_args[@]}"