| 1 | name: Forward to Cursor hygiene |
| 2 | |
| 3 | on: |
| 4 | push: |
| 5 | branches: [main] |
| 6 | pull_request: |
| 7 | types: [opened, reopened, ready_for_review] |
| 8 | issues: |
| 9 | types: [opened, closed, reopened] |
| 10 | discussion: |
| 11 | types: [created, closed, reopened] |
| 12 | |
| 13 | permissions: |
| 14 | contents: read |
| 15 | |
| 16 | jobs: |
| 17 | forward: |
| 18 | name: POST to Cursor |
| 19 | runs-on: ubuntu-24.04 |
| 20 | steps: |
| 21 | - name: POST to Cursor |
| 22 | env: |
| 23 | URL: ${{ secrets.CURSOR_T3CODE_WEBHOOK_URL }} |
| 24 | AUTH: ${{ secrets.CURSOR_T3CODE_WEBHOOK_AUTH }} |
| 25 | run: | |
| 26 | set -euo pipefail |
| 27 | if [ -z "${URL:-}" ] || [ -z "${AUTH:-}" ]; then |
| 28 | echo "Missing CURSOR_T3CODE_WEBHOOK_URL or CURSOR_T3CODE_WEBHOOK_AUTH — skipping." |
| 29 | exit 0 |
| 30 | fi |
| 31 | for attempt in 1 2 3; do |
| 32 | curl_status=0 |
| 33 | http_status=$(curl -fsS --max-time 60 -X POST "$URL" \ |
| 34 | --output /dev/null --write-out '%{http_code}' \ |
| 35 | -H "Authorization: $AUTH" \ |
| 36 | -H "Content-Type: application/json" \ |
| 37 | -H "X-GitHub-Event: ${{ github.event_name }}" \ |
| 38 | -H "X-GitHub-Delivery: ${{ github.run_id }}-${{ github.run_attempt }}" \ |
| 39 | --data-binary @"${{ github.event_path }}") || curl_status=$? |
| 40 | if [ "$curl_status" -eq 0 ]; then |
| 41 | exit 0 |
| 42 | fi |
| 43 | if [ "$GITHUB_REF" != "refs/heads/main" ] || \ |
| 44 | [ "$curl_status" -ne 22 ] || [ "$http_status" != "400" ] || \ |
| 45 | [ "$attempt" -eq 3 ]; then |
| 46 | exit "$curl_status" |
| 47 | fi |
| 48 | echo "Cursor webhook returned HTTP 400; retrying in 5 seconds ($attempt/2)." |
| 49 | sleep 5 |
| 50 | done |