← back to Bhv Review Poller

run.sh

45 lines

#!/usr/bin/env bash
# Beverly Hills Videos App Store review poller — runs check.mjs; on a state CHANGE,
# emails Steve via George + posts a CNCP parking-lot card. Always exits 0 (launchd-safe).
set -uo pipefail
DIR="/Users/macstudio3/Projects/bhv-review-poller"
LOG="$DIR/data/poller.log"
NODE="/opt/homebrew/bin/node"
JQ="/opt/homebrew/bin/jq"
NOTIFY_TO="${BHV_NOTIFY_TO:-steve@designerwallcoverings.com}"
cd "$DIR" || exit 0

OUT="$("$NODE" check.mjs 2>>"$LOG")" || { echo "$(date '+%F %T') CHECK_FAILED" >>"$LOG"; exit 0; }
echo "$(date '+%F %T') $OUT" >>"$LOG"

CHANGED="$(printf '%s' "$OUT" | "$JQ" -r '.changed')"
[ "$CHANGED" = "true" ] || exit 0

STATE="$(printf '%s' "$OUT" | "$JQ" -r '.state')"
PREV="$(printf '%s' "$OUT" | "$JQ" -r '.prev')"
MEANING="$(printf '%s' "$OUT" | "$JQ" -r '.meaning')"
VER="$(printf '%s' "$OUT" | "$JQ" -r '.versionString')"
STAMP="$(printf '%s' "$OUT" | "$JQ" -r '.stamp')"
APPROVED="$(printf '%s' "$OUT" | "$JQ" -r '.approved')"
REJECTED="$(printf '%s' "$OUT" | "$JQ" -r '.rejected')"

SUBJECT="📱 Beverly Hills Videos review: ${PREV} → ${STATE}"
BODY="<p><b>App Store review state changed.</b></p><p>Beverly Hills Videos v${VER}<br>${PREV} &rarr; <b>${STATE}</b><br>${MEANING}</p>"
[ "$APPROVED" = "true" ] && BODY="${BODY}<p>✅ Approved — the AdMob-link follow-up is now unblocked (mirror the nineoh pattern).</p>"
[ "$REJECTED" = "true" ] && BODY="${BODY}<p>⚠️ Needs action — read Apple's Resolution Center notes, fix, and resubmit.</p>"
BODY="${BODY}<p style='color:#888;font-size:12px'>Polled ${STAMP} PT · com.steve.bhv-review-poller</p>"

# George email (canonical shared helper)
if [ -f "$HOME/.claude/skills/_shared/george-send.sh" ]; then
  . "$HOME/.claude/skills/_shared/george-send.sh"
  george_send steve-office "$NOTIFY_TO" "$SUBJECT" "$BODY" >>"$LOG" 2>&1 || echo "$(date '+%F %T') GEORGE_SEND_FAILED" >>"$LOG"
fi

# CNCP parking-lot card (best-effort)
/usr/bin/curl -sS --max-time 10 http://127.0.0.1:3333/api/parking-lot \
  -H 'Content-Type: application/json' \
  -d "$(printf '%s' "$OUT" | "$JQ" -c '{title:("BHV review: "+.prev+" → "+.state), note:.meaning, source:"bhv-review-poller"}')" \
  >>"$LOG" 2>&1 || true

exit 0