diff --git a/scripts/prose-ai-review.sh b/scripts/prose-ai-review.sh index 989a462..4c48284 100755 --- a/scripts/prose-ai-review.sh +++ b/scripts/prose-ai-review.sh @@ -10,14 +10,22 @@ GITEA_TOKEN="${GITEA_TOKEN:-$(grep GITEA_TOKEN /root/.pi/agent/extensions/telegr GITEA_API="https://git.sysloggh.net/api/v1" # Get PR context from Gitea Actions environment -REPO="${{ gitea.repository }}" -PR_NUMBER="${{ gitea.event.number }}" -BASE_REF="${{ gitea.base_ref }}" -HEAD_REF="${{ gitea.head_ref }}" +# For push events: GITEA_REPOSITORY, GITEA_SHA +# For PR events: GITEA_REPOSITORY, GITEA_BASE_REF, GITEA_HEAD_REF +REPO="${GITEA_REPOSITORY:-${{ gitea.repository }}}" +BASE_REF="${GITEA_BASE_REF:-${GITEA_REF:-refs/heads/master}}" +HEAD_REF="${GITEA_HEAD_REF:-}" +SHA="${GITEA_SHA:-}" -# Get the diff -echo "=== Fetching PR diff ===" -DIFF=$(git diff origin/$BASE_REF...origin/$HEAD_REF -- "*.prose.md" 2>/dev/null | head -5000) +# Get the diff — works for both PR events (base...head) and push events (HEAD~1) +echo "=== Fetching diff ===" +if [ -n "$HEAD_REF" ] && [ "$HEAD_REF" != "$BASE_REF" ]; then + DIFF=$(git diff origin/$BASE_REF...origin/$HEAD_REF -- "*.prose.md" 2>/dev/null | head -5000) +elif [ -n "$SHA" ]; then + DIFF=$(git diff $SHA~1..$SHA -- "*.prose.md" 2>/dev/null | head -5000) +else + DIFF=$(git diff HEAD~1 -- "*.prose.md" 2>/dev/null | head -5000) +fi if [ -z "$DIFF" ]; then echo "No prose contract changes in this PR. Skipping AI review."