Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ Receives commit messages from Telex and sends analysis results to slack.

### Integration Config
```
GET /api/v1/webhook/telex/integration/json
GET /integration.json
```
Returns integration configuration for Telex.

Expand All @@ -239,8 +239,8 @@ You can customize the analyzer through Telex integration settings:
#### Example Commits
```json
{
"feat": "feat(auth): implement OAuth2 with role-based access",
"fix": "fix(api): resolve data race in concurrent requests"
"feat": "feat(auth): implement OAuth2 with role-based access\n\nImplemented OAuth2 protocol with role-based control to enhance security and scalability.",
"fix": "fix(api): resolve data race in concurrent requests\n\nFixed a race condition by adding synchronization mechanisms to prevent concurrent data modifications."
}
```

Expand Down
20 changes: 14 additions & 6 deletions src/config/integration_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,34 @@ def generate_json_config():
"Instant notifications when commits need attention",
"Easy setup with pre-configured commit patterns"
],
"website": settings.app_logo_url,
"author": "iamprecieee",
"settings": [
{
"label": "Commit Types",
"label": "slack_url",
"type": "text",
"required": True,
"description": "Slack Webhook URL",
"default": "https://slack.com"
},
{
"label": "commit_types",
"type": "text",
"required": True,
"required": False,
"description": "Provide custom commit types mapped to keywords that indicate type of change. Format: {'type': ['keyword1', 'keyword2']}. Example: {'docs': ['document', 'readme']} means commits with 'document' or 'readme' suggest documentation changes.",
"default": "{'feat': ['add', 'implement', 'new', 'introduce'], 'fix': ['fix', 'resolve', 'patch', 'address']}"
},
{
"label": "Example Commits",
"label": "example_commits",
"type": "text",
"required": True,
"required": False,
"description": "Set example commits for each custom commit type to guide new devs. These appear in suggestions when similar commits need fixing. Format: {'type1': 'example message1', 'type2': 'example message 2'}.",
"default": "{'feat': 'feat(auth): implement OAuth2 with role-based access\n\nImplemented OAuth2 protocol with role-based control to enhance security and scalability.', 'fix': 'fix(api): resolve data race in concurrent requests\n\nFixed a race condition by adding synchronization mechanisms to prevent concurrent data modifications.'}"
},
{
"label": "Training Data",
"label": "training_data",
"type": "text",
"required": True,
"required": False,
"description": "Add custom data to train the analyzer with commits that match preferred style. More examples = better suggestions. Format: {'type1': ['example1', 'example2'], 'type2': ['example3', 'example4']}. The analyzer learns from these to better match preferred conventions.",
"default": "{'feat': ['feat(auth): implement OAuth2 with role-based access\n\nImplemented OAuth2 protocol with role-based control to enhance security and scalability.','feat(search): implement elasticsearch integration\n\nIntegrated Elasticsearch to boost search performance and enhance result accuracy.']}"
}
Expand Down
14 changes: 9 additions & 5 deletions src/core/analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ def __init__(self, settings: list):
self.example_commits = example_commits.copy()
self.commit_training_data = commit_training_data.copy()
self.semantic_patterns = semantic_patterns.copy()

self.slack_url = None # Retrieved from settings

try:
self._apply_data_settings()
Expand All @@ -45,11 +47,13 @@ def _apply_data_settings(self):
"""
for setting in self.settings:
if setting["label"] == "commit_types":
self.commit_types.update(ast.literal_eval(setting["default"]))
elif setting["label"] == "example_commits":
self.example_commits.update(ast.literal_eval(setting["default"]))
elif setting["label"] == "training_data":
self.commit_training_data.update(ast.literal_eval(setting["default"]))
self.commit_types.update(ast.literal_eval(setting["default"])) if setting["default"] else self.commit_types
if setting["label"] == "example_commits":
self.example_commits.update(ast.literal_eval(setting["default"])) if setting["default"] else self.example_commits
if setting["label"] == "training_data":
self.commit_training_data.update(ast.literal_eval(setting["default"])) if setting["default"] else self.commit_training_data
if setting["label"] == "slack_url":
self.slack_url = setting["default"]

def _prepare_ml_classifier(self):
"""
Expand Down
4 changes: 2 additions & 2 deletions src/routers/telex.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from ..core.models import TelexTargetPayload
from ..core.analyzer import CommitAnalyzer
from ..config.integration_config import generate_json_config
from ..config.config import settings
from fastapi.responses import JSONResponse
from fastapi import status, HTTPException, Query
from typing import Annotated
Expand Down Expand Up @@ -31,6 +30,7 @@ async def telex_webhook(
)
try:
analyzer = CommitAnalyzer(settings=payload.settings)
slack_url = analyzer.slack_url
for commit in commit_message:
violations = analyzer.analyze_commit(commit["message"])
if violations:
Expand All @@ -42,7 +42,7 @@ async def telex_webhook(
status_code=status.HTTP_200_OK,
)
async with httpx.AsyncClient() as client:
await client.post(settings.slack_url, json=output_message)
await client.post(slack_url, json=output_message)
except Exception as e:
raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST,
Expand Down
9 changes: 8 additions & 1 deletion tests/test_telex.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,19 @@ def test_send_from_telex_failure():
json={
"message": '[{"id": "8ce4cf04f4rw6w8600675237350b14b4", "message": "fix(auth): child\n\nFixed a race condcvghdczhjvjhzcvhjvzhjvhjvczjonization mechanisms.", "timestamp": "2025-02-18T10:17:54+01:00", "url": "https://github.com/8", "author": {"name": "test", "email": "test@gmail.com"}}]',
"settings": [
{
"label": "slack_url",
"type": "text",
"required": True,
"description": "Slack Webhook URL",
"default": "https://slack.com"
},
{
"label": "commit_types",
"type": "text",
"description": "Custom commit types and keywords",
"required": False,
"default": "{'feat': ['add', 'implement', 'new', 'introduce'], 'fix': ['fix', 'resolve', 'patch', 'address']}",
"default": "",
},
{
"label": "Example Commits",
Expand Down