Skip to content

📧 Email Notification Cleanup #3818

📧 Email Notification Cleanup

📧 Email Notification Cleanup #3818

Workflow file for this run

name: 📧 Email Notification Cleanup
on:
schedule:
# Aggressive: Every hour (public repos only)
- cron: "0 * * * *"
# Moderate: Every 6 hours (private main repo)
- cron: "0 */6 * * *"
# Conservative: Once daily (fallback)
- cron: "0 9 * * *"
workflow_dispatch:
inputs:
max_emails:
description: "Maximum emails to process"
required: false
default: "50"
type: string
permissions:
contents: read
jobs:
# ═══════════════════════════════════════════════════════════════════
# JOB 0: Check if should run
# ═══════════════════════════════════════════════════════════════════
check-config:
name: 🔧 Check Config
runs-on: ubuntu-latest
timeout-minutes: 2
outputs:
should_run: ${{ steps.decide.outputs.should_run }}
steps:
- uses: actions/checkout@v4
- name: Detect Repository Type
id: detect
shell: pwsh
env:
GH_TOKEN: ${{ github.token }}
run: |
./scripts/detect-repo-config.ps1
- name: Decide if should run
id: decide
shell: pwsh
run: |
$scheduleMode = "${{ steps.detect.outputs.schedule_mode }}"
$eventName = "${{ github.event_name }}"
$cronMinute = "${{ github.event.schedule }}"
$shouldRun = "false"
# Manual dispatch: Always run
if ($eventName -eq "workflow_dispatch") {
$shouldRun = "true"
Write-Host "✅ Manual dispatch: Running"
}
# Scheduled: Check mode
elseif ($eventName -eq "schedule") {
switch ($scheduleMode) {
"aggressive" {
# Public repos: Run every hour
if ($cronMinute -match "0 \* \* \* \*") {
$shouldRun = "true"
Write-Host "✅ Aggressive mode: Running (hourly)"
}
}
"moderate" {
# Main private repo: Run every 6 hours
if ($cronMinute -match "0 \*/6 \* \* \*") {
$shouldRun = "true"
Write-Host "⚠️ Moderate mode: Running (6-hourly)"
}
}
"conservative" {
# Other private repos: Run daily only
if ($cronMinute -match "0 9 \* \* \*") {
$shouldRun = "true"
Write-Host "🔒 Conservative mode: Running (daily)"
}
}
}
}
Add-Content -Path $env:GITHUB_OUTPUT -Value "should_run=$shouldRun"
# ═══════════════════════════════════════════════════════════════════
# JOB 1: Cleanup Email Notifications
# ═══════════════════════════════════════════════════════════════════
cleanup-notifications:
name: 📧 Process Emails
needs: check-config
if: needs.check-config.outputs.should_run == 'true'
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- name: 🔍 Checkout
uses: actions/checkout@v4
- name: 🐍 Setup Python
uses: actions/setup-python@v6
with:
python-version: "3.11"
cache: "pip"
- name: 📦 Install Dependencies
run: |
cd tools/email-handler
pip install -r requirements.txt
- name: 🔐 Setup Gmail Credentials
env:
GMAIL_CREDENTIALS: ${{ secrets.GMAIL_CREDENTIALS }}
GMAIL_TOKEN: ${{ secrets.GMAIL_TOKEN }}
run: |
cd tools/email-handler
# Crear credentials.json desde secret
echo "$GMAIL_CREDENTIALS" > credentials.json
# Crear token.json desde secret si existe
if [ -n "$GMAIL_TOKEN" ]; then
echo "$GMAIL_TOKEN" > token.json
fi
- name: 📧 Process Notifications
env:
GH_TOKEN: ${{ github.token }}
MAX_EMAILS: ${{ github.event.inputs.max_emails || '50' }}
run: |
cd tools/email-handler
python src/main.py --max-emails $MAX_EMAILS
- name: 💾 Update Token (if refreshed)
if: always()
run: |
cd tools/email-handler
if [ -f token.json ]; then
echo "Token file exists, should be updated in secrets manually"
# Note: GitHub Actions cannot update secrets automatically
# User must copy the new token.json content to GMAIL_TOKEN secret
fi
- name: 📊 Summary
if: always()
run: |
echo "## 📧 Email Cleanup Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "✅ Email handler executed" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "Check logs for details on processed emails." >> $GITHUB_STEP_SUMMARY