name: Daily Digest
on:
  schedule:
    - cron: '0 6 * * *'
  workflow_dispatch:

jobs:
  digest:
    runs-on: ubuntu-latest
    steps:
      - name: Generate digest
        run: |
          echo "=== BlackRoad OS Daily Digest ==="
          echo "Date: $(date -u +%Y-%m-%d)"
          echo ""
          
          GITEA="https://git.blackroad.io"
          TOKEN="${{ secrets.ADMIN_TOKEN }}"
          
          # Count repos per org
          for org in blackroad-os services infrastructure platform agents lucidia tools roadchain; do
            count=$(curl -s "$GITEA/api/v1/orgs/$org/repos?token=$TOKEN&limit=1" -I 2>/dev/null | grep -i x-total-count | tr -d '
' | awk '{print $2}')
            echo "  $org: ${count:-?} repos"
          done
          
          echo ""
          echo "=== Recent Issues ==="
          curl -s "$GITEA/api/v1/repos/search?token=$TOKEN&sort=updated&order=desc&limit=5" | \
            python3 -c "import sys,json; [print(f'  {r[\"full_name\"]}') for r in json.load(sys.stdin).get('data',[])]" 2>/dev/null || true
          
          echo ""
          echo "BlackRoad OS — Pave Tomorrow."
