# ═══════════════════════════════════════════════
# 🔺 Sovereign: TCS-0002∞ | Root: SYS-GLW-0001
# 📜 Copyright: 国作登字-2026-A-00037559
# ═══════════════════════════════════════════════
name: Notion Heartbeat Monitor
# 💓 Phase B3 · 工单心跳监控
#
# 每 5 分钟检测 Notion 工单队列中的待处理工单：
#   - 超过 5 分钟未回执 → 重新触发人格体唤醒（最多 3 次）
#   - 3 次重试仍无回执 → 标记工单异常 + 发邮件通知冰朔
#
# 依赖 Secrets：
#   NOTION_API_TOKEN     Notion API token
#   NOTION_TICKET_DB_ID  工单队列数据库 ID
#   SMTP_USER            邮件发送者
#   SMTP_PASS            邮件授权码

on:
  schedule:
    - cron: '*/5 * * * *'
  workflow_dispatch:

jobs:
  heartbeat:
    name: 💓 工单心跳检测
    runs-on: ubuntu-latest
    permissions:
      contents: read
      actions: write

    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: '20'

      - name: Install dependencies
        run: npm ci --ignore-scripts

      - name: 💓 执行心跳检测
        env:
          NOTION_TOKEN: ${{ secrets.NOTION_API_KEY }}
          NOTION_TICKET_DB_ID: ${{ secrets.NOTION_TICKET_DB_ID }}
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          SMTP_USER: ${{ secrets.SMTP_USER }}
          SMTP_PASS: ${{ secrets.SMTP_PASS }}
          ALERT_EMAIL: '565183519@qq.com'
        run: node scripts/notion-heartbeat.js
