A Python bot that monitors a GitHub repository for new commits and sends notifications to a Slack channel.
- 馃攳 Monitors GitHub repository for new commits
- 馃摙 Sends formatted notifications to Slack
- 馃捑 Tracks last seen commit to avoid duplicate notifications
- 鈿欙笍 Configurable check interval
- 馃摑 Detailed logging
pip install -r requirements.txtEdit bot_config.json with your settings:
{
"github_repo": "owner/repo-name",
"github_token": "",
"slack_webhook_url": "https://hooks.slack.com/services/YOUR/WEBHOOK/URL",
"check_interval": 60,
"state_file": "last_commit_state.json"
}Configuration Options:
github_repo: GitHub repository in formatowner/repo-name(e.g.,octocat/Hello-World)github_token: (Optional) GitHub personal access token for higher rate limits. Get one at https://github.com/settings/tokensslack_webhook_url: Slack webhook URL for your channel. See Slack Webhook Setup belowcheck_interval: How often to check for new commits (in seconds). Default: 60state_file: File to store the last seen commit SHA. Default:last_commit_state.json
- Go to https://api.slack.com/apps
- Create a new app or select an existing one
- Go to "Incoming Webhooks" and activate it
- Click "Add New Webhook to Workspace"
- Select the channel where you want notifications
- Copy the webhook URL and paste it into
bot_config.json
python3 github_commit_bot.pyOr specify a custom config file:
python3 github_commit_bot.py my_config.json- The bot polls the GitHub API at the specified interval
- It compares the latest commit SHA with the last known commit
- If a new commit is detected, it sends a formatted message to Slack
- The bot saves the new commit SHA to avoid duplicate notifications
The bot sends formatted messages with:
- Repository name
- Commit SHA (short)
- Author name
- Commit date
- Commit message
- Link to view the commit on GitHub
The bot logs to both:
- Console (stdout)
- File:
github_bot.log
Press Ctrl+C to gracefully stop the bot.
- Without a GitHub token, you're limited to 60 requests/hour per IP
- With a GitHub token, you get 5,000 requests/hour
- The bot creates a state file to track the last seen commit
- On first run, the bot initializes with the latest commit (no notification sent)
No notifications received:
- Check that your Slack webhook URL is correct
- Verify the GitHub repository name is in the correct format
- Check the logs in
github_bot.log
Rate limit errors:
- Add a GitHub personal access token to increase rate limits
- Increase the
check_intervalto poll less frequently
Bot not detecting commits:
- Verify the repository name is correct
- Check that the repository is public or your token has access
- Review the logs for API errors