Skip to content

Commit 01ea97e

Browse files
authored
Merge pull request #13 from telexintegrations/staging
feat(analyzer): add extra checks for quality of commit messages
2 parents 25d08f5 + 27d68cf commit 01ea97e

File tree

13 files changed

+1129
-11
lines changed

13 files changed

+1129
-11
lines changed

.env.example

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,8 @@ HOST=0.0.0.0
66
PORT=8000
77
RELOAD_VALUE=True
88
TELEX_WEBHOOK_URL=https://ping.telex.im/v1/webhooks
9-
CURL_COMMAND=curl
9+
CURL_COMMAND=curl
10+
APP_LOGO_URL=logo_url
11+
APP_URL=app_url
12+
TARGET_URL=target_url
13+
BACKGROUND_COLOR_HEXCODE=hexcode

README.md

Lines changed: 282 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,282 @@
1+
# Git Commit Quality Monitor
2+
3+
A smart Telex integration that helps teams maintain high-quality git commit messages using ML-powered analysis and real-time feedback.
4+
5+
## Overview
6+
7+
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.
8+
9+
### Key Features
10+
11+
- ⚡️ Real-time feedback through Slack
12+
- 🎯 Customizable commit rules/conventions
13+
- 🔄 GitHub webhook integration
14+
- 🎨 Telex integration support
15+
- 🤖 Smart ML-powered commit message analysis and suggestions
16+
17+
## Quick Start Guide
18+
19+
### Prerequisites
20+
21+
- Python 3.8+
22+
- FastAPI
23+
- scikit-learn
24+
- Git (for development)
25+
- Telex account
26+
- GitHub repository access
27+
- Slack workspace (for notifications)
28+
29+
### Basic Setup
30+
31+
1. Clone the repository:
32+
```bash
33+
git clone <repository-url>
34+
cd commit-quality-monitor
35+
```
36+
37+
2. Set up a virtual environment:
38+
```bash
39+
python -m venv venv
40+
source venv/bin/activate # Linux/Mac
41+
# or
42+
.\venv\Scripts\activate # Windows
43+
```
44+
45+
3. Install dependencies:
46+
```bash
47+
pip install -r requirements.txt
48+
```
49+
50+
4. Configure environment variables:
51+
```bash
52+
cp .env.example .env
53+
# Edit .env with your configurations
54+
```
55+
56+
### Integration Setup
57+
58+
1. Configure repository webhooks with specific settings:
59+
- Go to your repository settings
60+
- Add webhook: `<your-app-url>/api/v1/webhook/github/{telex_channel_id}`
61+
- Set content type to `application/json`
62+
- Select "Just the push event"
63+
64+
2. Configure Slack notifications:
65+
- Create a Slack app
66+
- Add Incoming Webhooks
67+
- Add the generated webhook URL to your environment variables
68+
69+
## Detailed Configuration
70+
71+
| Variable | Description | Example |
72+
|----------|-------------|---------|
73+
| ALLOWED_ORIGINS | Comma-separated list of allowed origins | https://github.com,http://localhost:8000 |
74+
| ALLOWED_HOSTS | Comma-separated list of allowed hosts | github.com,localhost |
75+
| HOST | Server host | 0.0.0.0 |
76+
| PORT | Server port | 8000 |
77+
| TELEX_WEBHOOK_URL | Telex webhook URL | https://ping.telex.im/v1/webhooks |
78+
| SLACK_URL | Slack webhook URL for notifications | https://hooks.slack.com/... |
79+
| APP_LOGO_URL | URL for app logo | https://example.com/logo.png |
80+
| APP_URL | Application URL | https://your-app.com |
81+
| TARGET_URL | Telex target URL | https://your-app.com/webhook/telex |
82+
83+
## System Architecture
84+
85+
### Project Structure
86+
87+
```
88+
project_root/
89+
├── src/
90+
│ ├── core/ # Core Analysis Engine
91+
│ │ ├── analyzer.py # ML-based commit analysis logic
92+
│ │ └── models.py # Data models and structure
93+
│ │
94+
│ ├── config/ # Configuration Management
95+
│ │ ├── data.py # Training data, patterns, and examples
96+
│ │ ├── config.py # Environment settings management
97+
│ │ ├── integration_config.py # Telex integration configuration
98+
│ │ └── middleware.py # CORS and trusted host middleware
99+
│ │
100+
│ ├── routers/ # API Routing Layer
101+
│ │ ├── github.py # GitHub webhook endpoint handling
102+
│ │ ├── telex.py # Telex webhook and integration
103+
│ │ └── router.py # Main router configuration
104+
│ │
105+
│ └── utils/ # Utility Functions
106+
│ └── telex_utils.py # Telex communication helpers
107+
108+
├── tests/ # Test Suite
109+
│ ├── __init__.py # Test configuration
110+
│ ├── test_github.py # GitHub integration tests
111+
│ └── test_telex.py # Telex integration tests
112+
113+
├── .env.example # Environment variable template
114+
├── main.py # Application entry point
115+
├── requirements.txt # Project dependencies
116+
└── README.md # Project documentation
117+
```
118+
119+
### Core Analysis Engine
120+
121+
The system implements a multi-step process to evaluate the quality of commit messages:
122+
123+
#### Direct Pattern Matching
124+
- Matches against predefined commit types
125+
- Provides immediate classification
126+
- Optimized for standard conventions
127+
128+
```python
129+
commit_types = {
130+
"feat": ["add", "implement", "new", "introduce"],
131+
"fix": ["fix", "resolve", "patch", "address"],
132+
"docs": ["document", "update docs", "readme"],
133+
"refactor": ["refactor", "restructure", "simplify"]
134+
}
135+
```
136+
137+
#### Machine Learning Classification
138+
- Uses TF-IDF vectorization to transform commit messages into numerical vectors
139+
- Maintains a training dataset of exemplar commits
140+
- Employs cosine similarity analysis to compute similarity scores against known patterns
141+
- Suggests types based on highest similarity matches
142+
143+
```python
144+
def _prepare_ml_classifier(self):
145+
x_train = [] # Commit messages
146+
y_train = [] # Corresponding types
147+
148+
for commit_type, messages in self.commit_training_data.items():
149+
x_train.extend(messages)
150+
y_train.extend([commit_type] * len(messages))
151+
152+
self.vectorizer.fit(x_train)
153+
self.x_train_vectorized = self.vectorizer.transform(x_train)
154+
```
155+
156+
#### Semantic Analysis
157+
- Recognizes complex patterns
158+
- Understands contextual relationships
159+
- Handles non-standard commits
160+
161+
```python
162+
semantic_patterns = {
163+
"feat": [
164+
("create", "new"),
165+
("add", "feature"),
166+
("implement", "support")
167+
],
168+
"fix": [
169+
("resolve", "issue"),
170+
("patch", "vulnerability"),
171+
("correct", "behavior")
172+
]
173+
}
174+
```
175+
176+
#### Content Quality
177+
- 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.
178+
- Scans the commit message for words that might be gibberish.
179+
180+
#### Context Evaluation
181+
- 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.
182+
183+
## API Documentation
184+
185+
### GitHub Webhook Endpoint
186+
```http
187+
POST /api/v1/webhook/github/{telex_channel_id}
188+
Content-Type: application/json
189+
190+
{
191+
"pusher": {"name": "username"},
192+
"commits": [
193+
{
194+
"id": "commit_hash",
195+
"message": "commit_message",
196+
"timestamp": "iso_timestamp"
197+
}
198+
]
199+
}
200+
```
201+
Receives GitHub push events and forwards to Telex.
202+
203+
### Telex Integration Endpoint
204+
```http
205+
POST /api/v1/webhook/telex
206+
Content-Type: application/json
207+
208+
{
209+
"message": "serialized_commit_data",
210+
"settings": [
211+
{
212+
"label": "commit_types",
213+
"type": "text",
214+
"default": "{...}"
215+
}
216+
]
217+
}
218+
```
219+
Receives commit messages from Telex and sends analysis results to slack.
220+
221+
### Integration Config
222+
```
223+
GET /integration.json
224+
```
225+
Returns integration configuration for Telex.
226+
227+
### Customizing Commit Analysis
228+
229+
You can customize the analyzer through Telex integration settings:
230+
231+
#### Commit Types
232+
```json
233+
{
234+
"feat": ["add", "implement", "new"],
235+
"fix": ["fix", "resolve", "patch"]
236+
}
237+
```
238+
239+
#### Example Commits
240+
```json
241+
{
242+
"feat": "feat(auth): implement OAuth2 with role-based access\n\nImplemented OAuth2 protocol with role-based control to enhance security and scalability.",
243+
"fix": "fix(api): resolve data race in concurrent requests\n\nFixed a race condition by adding synchronization mechanisms to prevent concurrent data modifications."
244+
}
245+
```
246+
247+
#### Training Data
248+
```json
249+
{
250+
"feat": [
251+
"feat(ui): add dark mode toggle",
252+
"feat(api): implement rate limiting"
253+
]
254+
}
255+
```
256+
257+
## Development Guide
258+
259+
### Running the Application
260+
```bash
261+
uvicorn main:app --reload
262+
```
263+
264+
### Testing
265+
```bash
266+
pytest tests/
267+
```
268+
269+
### Contributing
270+
271+
To contribute to the project:
272+
1. Fork the repository
273+
2. Create a feature branch
274+
3. Commit changes following our guidelines
275+
4. Push to your branch
276+
5. Submit a Pull Request
277+
278+
279+
280+
---
281+
282+
📦 GitHub Push → 🔄 Telex → 🧠 Analysis/Suggestions Pipeline (🔍 → 🤖 → 🎯) → 📱 Slack Alert

main.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
from fastapi import FastAPI
22
from src.config.middleware import middleware
33
from src.routers.router import webhook_router
4+
from src.routers.telex import telex_json_router
45
from src.config.config import settings
56
import uvicorn
67

78

89
app = FastAPI(docs_url="/", middleware=middleware)
910
app.include_router(webhook_router)
11+
app.include_router(telex_json_router)
1012

1113
if __name__ == "__main__":
1214
reload_value = settings.reload_value.lower() == "true"

src/config/config.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ class Settings(BaseSettings):
1010
reload_value: str
1111
telex_webhook_url: str
1212
curl_command: str | None = "curl" # might require path/to/curl e.g. `/usr/bin/curl`
13+
app_logo_url: str
14+
app_url: str
15+
target_url: str
16+
background_color_hexcode: str
1317

1418
model_config = SettingsConfigDict(env_file=".env")
1519

0 commit comments

Comments
 (0)