A powerful Discord bot cog that integrates GitHub repositories with Discord forums, providing real-time synchronization of issues, pull requests, comments, and reviews.
- Real-time Synchronization: Automatically creates and updates Discord forum threads for GitHub issues and PRs
- Smart Review Batching: Groups review comments to prevent notification spam (2-second delay)
- Automatic Tag Management: Creates and manages status tags (Open/Closed/Merged) dynamically
- Thread Recreation: Recreates deleted threads during reconciliation
- Multi-Repository Support: Handle multiple GitHub repositories with proper namespacing
- Feed Channel Announcements: Optional announcement channels for new/closed items
- Role Mentioning: Configurable contributor role notifications
- Comprehensive Logging: Detailed console and Discord logging for debugging
- Environment Variable Support: Secure token management via
GENHUB_GITHUB_TOKEN - Flexible Configuration: Text commands and slash commands for easy setup
- Webhook Integration: Receives GitHub webhook events for instant updates
- Copy the
GenHubdirectory to thecogsdirectory of your Redbot instance. - Load the cog using the
[p]load GenHubcommand.
-
Add the repo to Redbot:
!repo add genhub https://github.com/undead2146/GenHubCog/ -
Install the cog:
!cog install genhub GenHub -
Load the cog:
!load GenHub
Set the GitHub token using the Discord configuration commands below. The token is stored persistently in the bot's configuration.
All commands are prefixed with [p] (your bot's prefix, e.g. !):
[p]genhub host <host>: Set the webhook host (default: 0.0.0.0)[p]genhub port <port>: Set the webhook port (default: 8080)[p]genhub secret <secret>: Set the GitHub webhook secret[p]genhub token <token>: Set the GitHub API token (alternative to env var)[p]genhub addrepo <owner/repo>: Add an allowed repository (e.g., owner/repo)[p]genhub removerepo <owner/repo>: Remove an allowed repository[p]genhub logchannel <channel_id>: Set the log channel ID for error reporting[p]genhub issuesforum <forum_id>: Set the Issues forum channel ID[p]genhub prsforum <forum_id>: Set the Pull Requests forum channel ID[p]genhub issuesfeedchat <channel_id>: Set the Issues Feed Chat channel ID[p]genhub prsfeedchat <channel_id>: Set the PR Feed Chat channel ID[p]genhub contributorrole <role_id>: Set the Contributor role ID for mentions[p]genhub reconcile [repo]: Reconcile all forum posts (optionally filter by repo)[p]genhub clearcache: Clear the thread cache to force fresh lookups[p]genhub testrepo <repo>: Test access to a GitHub repository[p]genhub showconfig: Show the current GenHub configuration
/genhubconfig: Configure all parameters in one go (autofill options in Discord UI)
-
Set Environment Variable:
export GENHUB_GITHUB_TOKEN=your_github_personal_access_token -
Configure Discord Channels:
!genhub issuesforum 1234567890123456789 !genhub prsforum 1234567890123456789
-
Add Repositories:
!genhub addrepo owner/repository -
Start Reconciliation:
!genhub reconcile
- In your GitHub repository settings, go to Settings > Webhooks
- Add webhook URL:
https://your-domain.com/github - Set Content type to
application/json - Set Secret to match your configured secret
- Select events: Issues, Pull requests, Issue comments, Pull request reviews, Pull request review comments
The reconcile command ensures your Discord forums stay synchronized with GitHub:
- Recreates Deleted Threads: If you delete a forum post, reconcile will recreate it
- Updates Tags: Ensures all threads have correct status tags (Open/Closed/Merged)
- Handles Missing Data: Gracefully handles API failures and permission issues
- Cleans Up Orphans: Removes threads for deleted GitHub items
- Comprehensive Logging: Shows detailed progress and any issues encountered
Threads are created with the format: [GH] [#{number}] {title}
The bot automatically creates and manages tags:
- Status Tags: Open, Closed, Merged (mutually exclusive)
- Repository Tags: One tag per repository for filtering
- Activity Tags: Active (for issues with assignees)
To prevent notification spam, review comments are batched together:
- Reviews with multiple comments are grouped into a single Discord message
- 2-second delay allows all review parts to arrive before posting
- One notification per review instead of one per comment
GenHub processes the following GitHub webhook events:
- Issues:
opened,closed,reopened,assigned,unassigned - Pull Requests:
opened,closed,reopened,assigned,unassigned,merged - Issue Comments:
created(comments on issues) - Pull Request Reviews:
submitted(review body) - Pull Request Review Comments:
created(individual review comments)
Each event type creates or updates the appropriate forum thread with formatted messages and status tags.
GenHub uses a modular architecture with clear separation of concerns:
- Webhook Server (
webhook.py): Receives and validates GitHub webhook events - Event Handlers (
handlers.py): Processes different event types with business logic - Thread Manager (
utils.py): Handles Discord forum thread lifecycle - Configuration System: Manages settings via Redbot's config system
GitHub Event → Webhook Validation → Event Routing → Thread Lookup/Creation → Message Posting
- Naming:
[GH] [#{number}] {title}format prevents conflicts - Caching: In-memory cache with Redbot persistence for performance
- Tags: Automatic creation and management of status/repository tags
- Recovery: Reconciliation recreates missing threads
GitHub sends review events separately, so GenHub uses a 2-second batching system:
- Review body arrives → start timer
- Review comments arrive → add to batch
- Timer expires → post all content together
- Prevents notification spam for detailed reviews
- Check your GitHub token permissions (needs
reposcope for private repos) - Ensure the token has access to the repository
- Verify the repository exists and is not private
- Try using
!genhub testrepo <repo>to diagnose access issues
- Verify forum channels are configured correctly with
!genhub showconfig - Check that the bot has permission to create threads in the forums
- Ensure repository has issues/PRs to sync
- Check console logs for detailed error messages
- This is normal behavior - reviews are batched but may still appear as separate messages
- The 2-second delay groups comments from the same review
- Individual comments from different reviews appear separately
- Use
!genhub clearcacheto reset the thread cache - This forces fresh lookups and can resolve stale cache issues
The bot provides extensive logging to help troubleshoot issues:
- Console Logs: Detailed progress and error information
- Discord Logs: Error messages sent to configured log channel
- API Responses: Shows GitHub API call results
- Thread Creation: Logs when threads are created or updated
# 1. Create Python 3.11 virtual environment
py -3.11 -m venv venv
# 2. Activate virtual environment
venv\Scripts\activate # Windows
# or
source venv/bin/activate # Linux/macOS
# 3. Start Redbot
redbot GenHubBot
# 4. Expose webhook port (optional)
ngrok http 8080GenHub/
├── __init__.py # Cog initialization and setup
├── genhub.py # Main cog class, configuration, lifecycle
├── webhook.py # aiohttp server for GitHub webhook reception
├── handlers.py # GitHub event processing and business logic
├── config_commands.py # Text-based configuration commands
├── slash_commands.py # Discord slash command interface
├── utils.py # Thread management, message formatting, utilities
└── info.json # Cog metadata and dependencies
tests/ # Comprehensive test suite
├── conftest.py # Test configuration and fixtures
├── test_*.py # Individual component tests
└── utils.py # Test utilities and mock objects
Run the test suite:
python -m pytest tests/ -v- Token Security: Always use environment variables for GitHub tokens
- Webhook Secrets: Use strong, unique secrets for webhook validation
- Permissions: Grant minimal required Discord permissions to the bot
- Repository Access: Only add repositories you want to sync
For issues, feature requests, or contributions:
- Create an issue on the GitHub repository
- Check the troubleshooting section above
- Review the console logs for detailed error information
This project is open source. See the repository for license details.