diabetes-research / help-desk-non-phi

Public (non-PHI) Help Desk repo to host issues, FAQs, knowledgebases and tasks that are non-sensitive. Integrated into DRH application
0 stars 0 forks source link

Create GitHub Actions-based notifications for incoming issues/discussions #2

Open razakpm opened 1 week ago

razakpm commented 1 week ago
razakpm commented 1 week ago

This guide describes how to set up a GitHub Action that automatically sends an email for all open GitHub Issues that have not been touched for more than 12 hours, using an email domain hosted in Office 365 (techbd.org).

  1. Create a GitHub Action workflow to run periodically and check for open issues that haven't been updated in the last 12 hours.
  2. Use GitHub's API to fetch the list of issues and filter them by the "updated_at" timestamp.
  3. Send an email notification using AWS SES service to send the emails.
# .github/workflows/notify-inactive-issues.yml

name: Notify Inactive Issues

on:
  schedule:
    - cron: '0 * * * *'  # Runs every hour, adjust as necessary

jobs:
  notify_inactive_issues:
    runs-on: ubuntu-latest

    steps:
    - name: Check out the repository
      uses: actions/checkout@v2

    - name: Fetch open issues
      id: fetch_issues
      run: |
        curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" "https://api.github.com/repos/${{ github.repository }}/issues?state=open" | jq '[.[] | select((now - (.updated_at | fromdateiso8601)) > (12 * 60 * 60))]' > inactive_issues.json

    - name: Send email if there are inactive issues
      if: success()
      uses: dawidd6/action-send-mail@v3
      with:
        server_address: smtp.office365.com  # Office 365 SMTP server
        server_port: 587
        username: ${{ secrets.OFFICE365_USERNAME }}  # Office 365 email address
        password: ${{ secrets.OFFICE365_PASSWORD }}  # Office 365 app-specific password or regular password
        subject: "GitHub Issues Notification"
        to: "help@diabetestechnology.org"
        from: "noreply@diabetestechnology.org"  # Sender email from diabetestechnology.org domain
        content_type: text/plain
        body: |
          The following issues have been inactive for more than 12 hours:
          ${{ steps.fetch_issues.outputs.inactive_issues }}