A smart Telex integration that helps teams maintain high-quality git commit messages using ML-powered analysis and real-time feedback.
Git Commit Quality Monitor analyzes commit messages in real-time, providing instant feedback on commit quality and suggestions for improvement. It uses machine learning to understand commit patterns and provides customized suggestions based on conventional commit standards and the development team's preferences.
- v2 (current): Simplified architecture with pre-configured analysis rules
- v1-legacy: Available in v1-legacy branch, supports configurable commit rules and dynamic analyzer settings
- β‘οΈ Real-time feedback through Slack
- π― Pre-configured commit standards based on conventional commits
- π GitHub webhook integration
- π¨ Telex integration support
- π€ Smart ML-powered commit message analysis and suggestions
- Python 3.12
- FastAPI
- scikit-learn
- Git (for development)
- Telex account
- GitHub repository access
- Slack workspace (for notifications)
Variable | Description | Example |
---|---|---|
ALLOWED_ORIGINS | Comma-separated list of allowed origins | https://github.com,http://localhost:8000 |
ALLOWED_HOSTS | Comma-separated list of allowed hosts | github.com,localhost |
HOST | Server host | 0.0.0.0 |
PORT | Server port | 8000 |
TELEX_WEBHOOK_URL | Telex webhook URL | https://ping.telex.im/v1/webhooks |
APP_LOGO_URL | URL for app logo | https://example.com/logo.png |
APP_URL | Application URL | https://your-app.com |
TARGET_URL | Telex target URL | https://your-app.com/webhook/telex |
project_root/
βββ src/
β βββ core/ # Core Analysis Engine
β β βββ analyzer/ # ML-based commit analysis logic
| | | βββ analyzer.py
| | | βββ format_analyzer.py
| | | βββ quality_analyzer.py
β β βββ models.py # Data models and structure
β β
β βββ config/ # Configuration Management
β β βββ data.py # Training data, patterns, and examples
β β βββ config.py # Environment settings management
β β βββ integration_config.py # Telex integration configuration
β β βββ middleware.py # CORS and trusted host middleware
β β
β βββ routers/ # API Routing Layer
β β βββ github.py # GitHub webhook endpoint handling
β β βββ telex.py # Telex webhook and integration
β β βββ router.py # Main router configuration
β β
β βββ utils/ # Utility Functions
β βββ telex_utils.py # Telex communication helpers
β
βββ tests/ # Test Suite
β βββ __init__.py # Test configuration
β βββ test_github.py # GitHub integration tests
β βββ test_telex.py # Telex integration tests
β
βββ .env.example # Environment variable template
βββ main.py # Application entry point
βββ requirements.txt # Project dependencies
βββ README.md # Project documentation
The v2 system implements a multi-step process to evaluate the quality of commit messages:
- Matches against predefined commit types
- Provides immediate classification
- Optimized for standard conventions
commit_types = {
"feat": ["add", "implement", "new", "introduce"],
"fix": ["fix", "resolve", "patch", "address"],
"docs": ["document", "update docs", "readme"],
"refactor": ["refactor", "restructure", "simplify"]
}
- Uses TF-IDF vectorization to transform commit messages into numerical vectors
- Maintains a training dataset of exemplar commits
- Employs cosine similarity analysis to compute similarity scores against known patterns
- Suggests types based on highest similarity matches
def _prepare_ml_classifier(self):
x_train = [] # Commit messages
y_train = [] # Corresponding types
for commit_type, messages in self.commit_training_data.items():
x_train.extend(messages)
y_train.extend([commit_type] * len(messages))
self.vectorizer.fit(x_train)
self.x_train_vectorized = self.vectorizer.transform(x_train)
- Recognizes complex patterns
- Understands contextual relationships
- Handles non-standard commits
semantic_patterns = {
"feat": [
("create", "new"),
("add", "feature"),
("implement", "support")
],
"fix": [
("resolve", "issue"),
("patch", "vulnerability"),
("correct", "behavior")
]
}
- It verifies that the commit message contains enough words. Messages with fewer than 5 words are flagged with a high-severity warning, while those with 5β9 words are flagged with a medium-severity warning.
- Scans the commit message for words that might be gibberish.
- Ensures that the commit message provides adequate context. It looks for a clear separation between the subject line and the detailed body (detected via a double newline \n\n). If this separation is missing, the method suggests splitting the message to improve clarity.
POST /api/v2/webhook/github/{telex_channel_id}/
Content-Type: application/json
{
"pusher": {"name": "username"},
"commits": [
{
"id": "commit_hash",
"message": "commit_message",
"timestamp": "iso_timestamp"
}
]
}
Receives GitHub push events, analyzes commits, and forwards to Telex.
POST /api/v2/webhook/telex/
Content-Type: application/json
{
"message": "serialized_commit_data",
"settings": [
{
"label": "commit_types",
"type": "text",
"default": "{...}"
}
]
}
Receives commit messages from Telex and forwards to slack.
GET /integration.json
Returns integration configuration for Telex.
- Clone the repository:
git clone <repository-url>
cd commit-quality-monitor
- Set up a virtual environment:
python -m venv venv
source venv/bin/activate # Linux/Mac
# or
.\venv\Scripts\activate # Windows
- Install dependencies:
pip install -r requirements.txt
- Configure environment variables:
cp .env.example .env
# Edit .env with your configurations
uvicorn main:app --reload
- Log into your Telex account
- Click on the β sign to add new channel
- Fill in channel details:
- Name: "Commit Quality Monitor"
- Copy the channel ID - you'll need this for GitHub webhook setup
- Go to your GitHub repository
- Click on "Settings" (requires admin access)
- Located in the top menu bar
- Look for the βοΈ gear icon
- In the left sidebar, click on "Webhooks"
- Click the "Add webhook" button (top right)
- Fill in the following fields:
- Payload URL:
https://your-domain/api/v2/webhook/github/{telex_channel_id}/
- Replace
your-domain
with your actual domain - Replace
{telex_channel_id}
with your Telex channel ID
- Payload URL:
- Set Content Type:
- Select "application/json" from the dropdown menu
- Select Events:
- Choose "Just the push event"
- This ensures you only receive relevant commit notifications
- Check "Active":
- Ensure the webhook is enabled
- Click "Add webhook" to save
- Check the webhook in your repository settings
- Look for a green checkmark indicating successful configuration
- If you see a red X, check the "Recent Deliveries" tab for error details
- Visit Slack API Portal
- Click "Create New App"
- Choose "From scratch"
- Fill in app details:
- App Name: "Commit Quality Guardian"
- Choose your workspace
- Click "Create App"
- In your app's settings page:
- Click "Incoming Webhooks" in the left sidebar
- Toggle "Activate Incoming Webhooks" to
On
- Add New Webhook:
- Click "Add New Webhook to Workspace"
- Choose the channel where notifications should appear
- Click "Allow"
- Copy Webhook URL:
- Find the new webhook URL in the list
- Copy it - you'll need this for configuration in Telex
- Format:
https://hooks.slack.com/services/XXX/YYY/ZZZ
- In the left menu on your telex dashboard:
- Click "Apps"
- Click "Add New"
- Enter the Integration JSON url:
https://your-domain/integration.json
- Configure Integration:
- Click on "Manage App" beside the added integration
- Click on "Settings"
- Add the slack webhook in the
slack_url
field
- Click "Save Settings"
- Enable the integration on the Apps dashboard
For teams requiring customizable features:
- Switch to v1-legacy branch:
git checkout v1-legacy
- Follow setup instructions in v1-legacy README
- Clone your repository:
git clone https://github.com/your-org/your-repo.git cd your-repo
- Make a test commit:
# Make a change echo "test" > test.txt # Add and commit git add test.txt git commit -m "add test file" # Push changes git push origin main
- Check GitHub:
- Go to repository settings
- Click Webhooks
- Look for successful delivery (green checkmark)
- Check Slack:
- Go to your configured Slack channel
- You should see a quality analysis message
- Check Telex:
- Open your Telex channel
- Verify the message was processed
- Webhook Not Triggering:
- Verify webhook URL is correct
- Check repository permissions
- Ensure webhook is active
- Slack Messages Not Appearing:
- Verify Slack webhook URL
- Check app permissions in Slack
- Ensure channel exists and is accessible
- Check application logs for errors
- Telex Integration Issues:
- Verify Telex channel ID
- Check integration status in Telex
- Ensure webhook URLs match
- Verify settings configuration
pytest tests/
To contribute to the project:
- Fork the repository
- Create a feature branch
- Commit changes following our guidelines
- Push to your branch
- Submit a Pull Request
π¦ GitHub Push β π Telex β π§ Analysis/Suggestions Pipeline (π β π€ β π―) β π± Slack Alert