Python script that monitors GitHub repositories and sends email notifications for new commits. Uses GitHub API to track changes across multiple repos, with configurable check intervals and email notifications. Perfect for staying updated on repository changes without manual checking.
- Real-time monitoring of multiple GitHub repositories
- Email notifications with detailed commit information
- Persistent state tracking to prevent duplicate notifications
- Configurable check intervals
- Support for various email providers
- Python 3.6+
requestslibrary
-
Install required packages:
pip install requests
-
Configure GitHub token and repositories:
GITHUB_TOKEN = "your_github_token_here" REPOS_TO_MONITOR = [ "owner1/repo1", "owner2/repo2" ]
-
Set up email configuration:
EMAIL_CONFIG = { 'smtp_server': 'smtp.gmail.com', 'smtp_port': '587', 'sender_email': 'your_email@gmail.com', 'sender_password': 'your_app_specific_password', 'recipient_email': 'recipient@example.com' }
-
Run the script:
python github_monitor.py
- Navigate to GitHub Settings → Developer Settings → Personal Access Tokens
- Click "Generate new token" and select the
reposcope - Copy the generated token
- Replace
your_github_token_herein the script with your token
- Enable 2-Step Verification in your Google Account
- Generate an App Password:
- Go to Google Account Settings → Security
- Find "App Passwords" under 2-Step Verification
- Select "Other" as the app and generate password
- Use this password in the EMAIL_CONFIG
Common SMTP configurations:
| Provider | Server | Port |
|---|---|---|
| Gmail | smtp.gmail.com | 587 |
| Outlook | smtp-mail.outlook.com | 587 |
| Yahoo | smtp.mail.yahoo.com | 587 |
| AOL | smtp.aol.com | 587 |
| iCloud | smtp.mail.me.com | 587 |
The script:
- Checks repositories at specified intervals
- Compares latest commit with last known state
- Sends email notifications for new commits
- Saves state to prevent duplicate notifications
- Handles errors gracefully
The script includes robust error handling for:
- Failed GitHub API requests
- Email sending failures
- Network connectivity issues
- Invalid repository names
- Authentication problems
This project is released under the MIT License.
Feel free to:
- Open issues for bugs or suggestions
- Submit pull requests with improvements
- Fork the project for your own use
If you encounter any issues:
- Check the error messages in the console
- Verify your configuration settings
- Ensure all credentials are correct
- Check your network connection