diff --git a/.github/workflows/triage.yml b/.github/workflows/triage.yml new file mode 100644 index 0000000..3c31310 --- /dev/null +++ b/.github/workflows/triage.yml @@ -0,0 +1,72 @@ +name: Notification Triage + +on: + schedule: + - cron: '0 * * * *' # every hour + workflow_dispatch: # manual trigger with inputs + inputs: + limit: + description: 'Max notifications to triage' + default: '50' + required: false + dry_run: + description: 'Dry run (preview actions without executing)' + type: boolean + default: false + +env: + PYTHON_VERSION: "3.11" + +jobs: + triage: + name: Triage GitHub Notifications + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-python@v5 + with: + python-version: ${{ env.PYTHON_VERSION }} + cache: pip + + - name: Install dependencies + run: pip install requests pyyaml python-dotenv anthropic + + - name: Run triage + id: triage + env: + # GITHUB_TOKEN is the Actions token — has notifications:read + write scope + GITHUB_TOKEN: ${{ secrets.TRIAGE_GITHUB_TOKEN || secrets.GITHUB_TOKEN }} + ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }} + run: | + LIMIT="${{ github.event.inputs.limit || '50' }}" + DRY_RUN="${{ github.event.inputs.dry_run || 'false' }}" + + ARGS="--limit $LIMIT" + [ "$DRY_RUN" = "true" ] && ARGS="$ARGS --dry-run" + + echo "## 🔔 Notification Triage Run" >> $GITHUB_STEP_SUMMARY + echo "" >> $GITHUB_STEP_SUMMARY + echo "- Limit: $LIMIT" >> $GITHUB_STEP_SUMMARY + echo "- Dry run: $DRY_RUN" >> $GITHUB_STEP_SUMMARY + echo "- LLM: ${{ secrets.ANTHROPIC_API_KEY && 'Claude (LLM)' || 'Rule-based fallback' }}" >> $GITHUB_STEP_SUMMARY + echo "" >> $GITHUB_STEP_SUMMARY + echo "\`\`\`" >> $GITHUB_STEP_SUMMARY + + python notification_copilot.py $ARGS 2>&1 | tee -a $GITHUB_STEP_SUMMARY + + echo "\`\`\`" >> $GITHUB_STEP_SUMMARY + + - name: Create issue on failure + if: failure() + uses: actions/github-script@v7 + with: + script: | + github.rest.issues.create({ + owner: context.repo.owner, + repo: context.repo.repo, + title: `Notification triage failed — ${new Date().toISOString().slice(0,16).replace('T',' ')} UTC`, + body: `## ⚠️ Scheduled triage failed\n\n**Run:** ${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}\n\nCheck the run logs for details. Common causes:\n- \`TRIAGE_GITHUB_TOKEN\` secret missing or expired\n- \`ANTHROPIC_API_KEY\` invalid (rule-based fallback should still work)\n- GitHub API rate limit hit`, + labels: ['bug', 'automated'], + });