A comprehensive GitHub bot written in Go that automates common repository management tasks.
- 🏷️ Auto-labeling: Automatically labels issues and PRs based on content
- 👋 Welcome messages: Greets new contributors
- 📝 Comment automation: Smart comments on issues and PRs
- 🗂️ File analysis: Analyzes changed files in pull requests
- ⏰ Stale issue management: Identifies and closes stale issues
- 🚀 RESTful API: HTTP endpoints for manual bot control
-
Clone and setup:
git clone <repository-url> cd github-bot go mod tidy
-
Set environment variables:
export GITHUB_TOKEN="your_github_token" export GITHUB_WEBHOOK_SECRET="your_webhook_secret" export PORT="8080"
-
Run the bot:
go run simple-bot.go
The bot automatically adds labels based on content:
bug- Contains bug/error keywordsenhancement- Feature requestsdocumentation- Doc related issuesquestion- Help/questionsurgent- High priority issuessize/small|medium|large- Based on description length
New contributors get a friendly welcome message with:
- Repository guidelines
- Contribution tips
- Getting started resources
- Suggests reviewers based on file types
- Identifies first-time contributors
- Analyzes code changes
- Marks issues as stale after 30 days
- Sends warning comments
- Closes if no activity continues
POST /webhook- GitHub webhook receiverGET /health- Health checkPOST /test-issue- Create test issue
Bot handles these GitHub events:
issues- New, updated, labeled issuespull_request- PR openings, updates, mergespush- Code pushesrepository- Repo creation, archiving
| Variable | Description | Required |
|---|---|---|
GITHUB_TOKEN |
GitHub personal access token | ✅ |
GITHUB_WEBHOOK_SECRET |
Webhook verification secret | ✅ |
PORT |
Server port | ❌ (default: 8080) |
LOG_LEVEL |
Logging level | ❌ (default: info) |
docker build -t github-bot .
docker run -e GITHUB_TOKEN=$GITHUB_TOKEN -p 8080:8080 github-botrailway upvercel --prodgithub-bot/
├── cmd/ # Application entrypoint
├── internal/
│ ├── handlers/ # HTTP request handlers
│ ├── services/ # Business logic
│ └── config/ # Configuration
├── pkg/
│ ├── github/ # GitHub API wrapper
│ └── logger/ # Logging utilities
└── webhooks/ # Webhook event processing
-
Add webhook handler:
handler.RegisterEventHandler("new_event", func(w http.ResponseWriter, r *http.Request, payload interface{}) { // Handle event })
-
Add bot service:
func (s *BotService) NewFeature(ctx context.Context, event *github.Event) error { // Implement feature }
-
Create API endpoint:
api.HandleFunc("/new-feature", handleNewFeature(service)).Methods("POST")
- 🔒 Webhook signature verification
- 🔑 Token-based authentication
- 🛡️ Input validation and sanitization
- 📝 Comprehensive logging
The bot provides:
- Structured JSON logging
- Health check endpoints
- Error tracking
- Performance metrics
- Fork the repository
- Create a feature branch
- Add tests for new functionality
- Ensure all tests pass
- Submit a pull request
MIT License - see LICENSE file for details