Skip to main content

Reusable GitHub Email Alert package for CI/CD workflows

Project description

GitHub Email Alert

Reusable Python package to send email alerts from GitHub Actions.

Features

  • Send alerts for:
    • Branch Created
    • Branch Deleted
    • New Pull Request
    • PR Merge
    • Merge Conflicts
  • SMTP configurable
  • CLI support
  • Works with GitHub Actions
  • CC support
  • Environment variable driven

Note: Branch create/delete events do not include a title field in the email body.

Installation

pip install github-email-alert

Usage

Basic Command

github-email-alert <branch_ref> <event_type>

Event Types

The following event types are supported:

  • branch_create - Branch created event
  • branch_delete - Branch deleted event
  • new_pr - New pull request created
  • merge_pr - Pull request merged
  • conflict - Merge conflict detected

Examples

Branch Created

github-email-alert feature/new-feature branch_create

Branch Deleted

github-email-alert feature/old-feature branch_delete

New Pull Request

github-email-alert feature/login new_pr

Pull Request Merged

github-email-alert feature/login merge_pr

Merge Conflict Detected

github-email-alert feature/login conflict

GitHub Actions Workflow Examples

Branch Created/Deleted Workflow

name: Branch Notification

on:
  create:
    branches: ['**']
  delete:
    branches: ['**']

jobs:
  notify:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      
      - name: Send branch created notification
        if: github.event.action == 'created'
        env:
          EMAIL_USER: ${{ secrets.EMAIL_USER }}
          EMAIL_PASS: ${{ secrets.EMAIL_PASS }}
          EMAIL_TO: ${{ secrets.EMAIL_TO }}
          GITHUB_ACTOR: ${{ github.actor }}
          BASE_REF: ${{ github.event.ref }}
          REPO_NAME: ${{ github.repository }}
        run: |
          pip install github-email-alert
          github-email-alert ${{ github.event.ref }} branch_create
      
      - name: Send branch deleted notification
        if: github.event.action == 'deleted'
        env:
          EMAIL_USER: ${{ secrets.EMAIL_USER }}
          EMAIL_PASS: ${{ secrets.EMAIL_PASS }}
          EMAIL_TO: ${{ secrets.EMAIL_TO }}
          GITHUB_ACTOR: ${{ github.actor }}
          BASE_REF: main
          REPO_NAME: ${{ github.repository }}
        run: |
          pip install github-email-alert
          github-email-alert ${{ github.event.ref }} branch_delete

Pull Request Workflow

name: PR Notification

on:
  pull_request:
    types: [opened, closed]

jobs:
  notify:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      
      - name: Send new PR notification
        if: github.event.action == 'opened'
        env:
          EMAIL_USER: ${{ secrets.EMAIL_USER }}
          EMAIL_PASS: ${{ secrets.EMAIL_PASS }}
          EMAIL_TO: ${{ secrets.EMAIL_TO }}
          EMAIL_CC: ${{ secrets.EMAIL_CC }}
          GITHUB_ACTOR: ${{ github.actor }}
          PR_TITLE: ${{ github.event.pull_request.title }}
          BASE_REF: ${{ github.event.pull_request.base.ref }}
          REPO_NAME: ${{ github.repository }}
        run: |
          pip install github-email-alert
          github-email-alert ${{ github.event.pull_request.head.ref }} new_pr
      
      - name: Send PR merged notification
        if: github.event.action == 'closed' && github.event.pull_request.merged == true
        env:
          EMAIL_USER: ${{ secrets.EMAIL_USER }}
          EMAIL_PASS: ${{ secrets.EMAIL_PASS }}
          EMAIL_TO: ${{ secrets.EMAIL_TO }}
          GITHUB_ACTOR: ${{ github.actor }}
          PR_TITLE: ${{ github.event.pull_request.title }}
          BASE_REF: ${{ github.event.pull_request.base.ref }}
          REPO_NAME: ${{ github.repository }}
        run: |
          pip install github-email-alert
          github-email-alert ${{ github.event.pull_request.head.ref }} merge_pr

Merge Conflict Detection Workflow

name: Conflict Detection

on:
  pull_request:
    types: [synchronize, opened]

jobs:
  check-conflict:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
        with:
          fetch-depth: 0
      
      - name: Check for merge conflicts
        id: check
        run: |
          git fetch origin ${{ github.event.pull_request.base.ref }}
          git merge --no-commit --no-ff origin/${{ github.event.pull_request.base.ref }} || echo "conflict=true" >> $GITHUB_OUTPUT
      
      - name: Send conflict notification
        if: steps.check.outputs.conflict == 'true'
        env:
          EMAIL_USER: ${{ secrets.EMAIL_USER }}
          EMAIL_PASS: ${{ secrets.EMAIL_PASS }}
          EMAIL_TO: ${{ secrets.EMAIL_TO }}
          GITHUB_ACTOR: ${{ github.actor }}
          PR_TITLE: ${{ github.event.pull_request.title }}
          BASE_REF: ${{ github.event.pull_request.base.ref }}
          REPO_NAME: ${{ github.repository }}
        run: |
          pip install github-email-alert
          github-email-alert ${{ github.event.pull_request.head.ref }} conflict

Configuration

Required Environment Variables

EMAIL_USER          # SMTP email address (e.g., your-email@gmail.com)
EMAIL_PASS          # SMTP password or app-specific password
EMAIL_TO            # Comma-separated list of recipient emails

Optional Environment Variables

EMAIL_CC            # Comma-separated list of CC emails
SMTP_HOST           # SMTP server hostname (default: smtp.gmail.com)
SMTP_PORT           # SMTP server port (default: 587)
GITHUB_ACTOR        # GitHub username (default: "Unknown")
PR_TITLE            # Pull request title (default: "N/A")
BASE_REF            # Target/base branch name (default: "main")
REPO_NAME           # Repository name (default: "Unknown")

Note

Branch create/delete events do not include a title field in the email body since they don't have an associated pull request.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

github_email_alert-0.1.2.tar.gz (43.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

github_email_alert-0.1.2-py3-none-any.whl (8.2 kB view details)

Uploaded Python 3

File details

Details for the file github_email_alert-0.1.2.tar.gz.

File metadata

  • Download URL: github_email_alert-0.1.2.tar.gz
  • Upload date:
  • Size: 43.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for github_email_alert-0.1.2.tar.gz
Algorithm Hash digest
SHA256 8e66d7c46f91e1892ef1b55f502c09f763e186b18593552cd0061fa891b10260
MD5 589f73c33d439ffa797e1ac24f961922
BLAKE2b-256 c9d7c7ca3d7d2f680d5492269dfc2cdec54c5977358cb5ae01c2158d1ead0534

See more details on using hashes here.

File details

Details for the file github_email_alert-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for github_email_alert-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 3a819a5130cba35e42c2570f02e4c651efc5350ef2073744b1437e7041453f4b
MD5 5ce513b63a9edf5d3a38bc8b50ef1dd7
BLAKE2b-256 b482c044101016fc7366d80b4e360ff09546de986a5283fcd73110c42aa17e42

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page