Skip to content

Commit 2f1fe9a

Browse files
authored
Merge pull request #12 from telexintegrations:chore/slack
fix(settings): add check for empty settings values
2 parents e9b5654 + 1318930 commit 2f1fe9a

File tree

5 files changed

+36
-17
lines changed

5 files changed

+36
-17
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ Receives commit messages from Telex and sends analysis results to slack.
220220

221221
### Integration Config
222222
```
223-
GET /api/v1/webhook/telex/integration/json
223+
GET /integration.json
224224
```
225225
Returns integration configuration for Telex.
226226

@@ -239,8 +239,8 @@ You can customize the analyzer through Telex integration settings:
239239
#### Example Commits
240240
```json
241241
{
242-
"feat": "feat(auth): implement OAuth2 with role-based access",
243-
"fix": "fix(api): resolve data race in concurrent requests"
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."
244244
}
245245
```
246246

src/config/integration_config.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,26 +25,34 @@ def generate_json_config():
2525
"Instant notifications when commits need attention",
2626
"Easy setup with pre-configured commit patterns"
2727
],
28+
"website": settings.app_logo_url,
2829
"author": "iamprecieee",
2930
"settings": [
3031
{
31-
"label": "Commit Types",
32+
"label": "slack_url",
33+
"type": "text",
34+
"required": True,
35+
"description": "Slack Webhook URL",
36+
"default": "https://slack.com"
37+
},
38+
{
39+
"label": "commit_types",
3240
"type": "text",
33-
"required": True,
41+
"required": False,
3442
"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.",
3543
"default": "{'feat': ['add', 'implement', 'new', 'introduce'], 'fix': ['fix', 'resolve', 'patch', 'address']}"
3644
},
3745
{
38-
"label": "Example Commits",
46+
"label": "example_commits",
3947
"type": "text",
40-
"required": True,
48+
"required": False,
4149
"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'}.",
4250
"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.'}"
4351
},
4452
{
45-
"label": "Training Data",
53+
"label": "training_data",
4654
"type": "text",
47-
"required": True,
55+
"required": False,
4856
"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.",
4957
"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.']}"
5058
}

src/core/analyzer.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ def __init__(self, settings: list):
2727
self.example_commits = example_commits.copy()
2828
self.commit_training_data = commit_training_data.copy()
2929
self.semantic_patterns = semantic_patterns.copy()
30+
31+
self.slack_url = None # Retrieved from settings
3032

3133
try:
3234
self._apply_data_settings()
@@ -45,11 +47,13 @@ def _apply_data_settings(self):
4547
"""
4648
for setting in self.settings:
4749
if setting["label"] == "commit_types":
48-
self.commit_types.update(ast.literal_eval(setting["default"]))
49-
elif setting["label"] == "example_commits":
50-
self.example_commits.update(ast.literal_eval(setting["default"]))
51-
elif setting["label"] == "training_data":
52-
self.commit_training_data.update(ast.literal_eval(setting["default"]))
50+
self.commit_types.update(ast.literal_eval(setting["default"])) if setting["default"] else self.commit_types
51+
if setting["label"] == "example_commits":
52+
self.example_commits.update(ast.literal_eval(setting["default"])) if setting["default"] else self.example_commits
53+
if setting["label"] == "training_data":
54+
self.commit_training_data.update(ast.literal_eval(setting["default"])) if setting["default"] else self.commit_training_data
55+
if setting["label"] == "slack_url":
56+
self.slack_url = setting["default"]
5357

5458
def _prepare_ml_classifier(self):
5559
"""

src/routers/telex.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
from ..core.models import TelexTargetPayload
33
from ..core.analyzer import CommitAnalyzer
44
from ..config.integration_config import generate_json_config
5-
from ..config.config import settings
65
from fastapi.responses import JSONResponse
76
from fastapi import status, HTTPException, Query
87
from typing import Annotated
@@ -31,6 +30,7 @@ async def telex_webhook(
3130
)
3231
try:
3332
analyzer = CommitAnalyzer(settings=payload.settings)
33+
slack_url = analyzer.slack_url
3434
for commit in commit_message:
3535
violations = analyzer.analyze_commit(commit["message"])
3636
if violations:
@@ -42,7 +42,7 @@ async def telex_webhook(
4242
status_code=status.HTTP_200_OK,
4343
)
4444
async with httpx.AsyncClient() as client:
45-
await client.post(settings.slack_url, json=output_message)
45+
await client.post(slack_url, json=output_message)
4646
except Exception as e:
4747
raise HTTPException(
4848
status_code=status.HTTP_400_BAD_REQUEST,

tests/test_telex.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,19 @@ def test_send_from_telex_failure():
3737
json={
3838
"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": "[email protected]"}}]',
3939
"settings": [
40+
{
41+
"label": "slack_url",
42+
"type": "text",
43+
"required": True,
44+
"description": "Slack Webhook URL",
45+
"default": "https://slack.com"
46+
},
4047
{
4148
"label": "commit_types",
4249
"type": "text",
4350
"description": "Custom commit types and keywords",
4451
"required": False,
45-
"default": "{'feat': ['add', 'implement', 'new', 'introduce'], 'fix': ['fix', 'resolve', 'patch', 'address']}",
52+
"default": "",
4653
},
4754
{
4855
"label": "Example Commits",

0 commit comments

Comments
 (0)