Skip to content

Commit 56824c3

Browse files
authored
Merge pull request #89 from MyElectricalData/develop
Develop
2 parents a30c827 + dd36fca commit 56824c3

File tree

20 files changed

+1760
-7016
lines changed

20 files changed

+1760
-7016
lines changed

.github/workflows/release.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,3 +259,47 @@ jobs:
259259
echo "docker pull ${{ env.IMAGE_PREFIX }}/backend:$VERSION" >> $GITHUB_STEP_SUMMARY
260260
echo "docker pull ${{ env.IMAGE_PREFIX }}/frontend:$VERSION" >> $GITHUB_STEP_SUMMARY
261261
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
262+
263+
# ===========================================
264+
# Sync develop with main (only after main release)
265+
# ===========================================
266+
sync-develop:
267+
name: Sync develop
268+
needs: [release]
269+
# Only sync when releasing from main (not develop)
270+
if: >
271+
needs.release.outputs.new_release_published == 'true' &&
272+
github.ref_name == 'main'
273+
runs-on: ubuntu-latest
274+
steps:
275+
- name: Checkout
276+
uses: actions/checkout@v4
277+
with:
278+
fetch-depth: 0
279+
token: ${{ secrets.GITHUB_TOKEN }}
280+
281+
- name: Configure Git
282+
run: |
283+
git config user.name "github-actions[bot]"
284+
git config user.email "github-actions[bot]@users.noreply.github.com"
285+
286+
- name: Sync develop with main
287+
env:
288+
RELEASE_VERSION: ${{ needs.release.outputs.new_release_version }}
289+
run: |
290+
# Fetch all branches
291+
git fetch origin main develop
292+
293+
# Log current state
294+
echo "=== Main branch HEAD ==="
295+
git log -1 --oneline origin/main
296+
297+
echo "=== Develop branch HEAD ==="
298+
git log -1 --oneline origin/develop
299+
300+
# Checkout develop and merge main
301+
git checkout develop
302+
git merge origin/main -m "chore: sync develop with main after v${RELEASE_VERSION} [skip ci]"
303+
git push origin develop
304+
305+
echo "✅ Develop synced with main"

.github/workflows/sync-develop.yml

Lines changed: 0 additions & 27 deletions
This file was deleted.

CHANGELOG.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,44 @@
11
# Changelog
22

3+
## [1.3.0-dev.2](https://github.com/MyElectricalData/myelectricaldata_new/compare/1.3.0-dev.1...1.3.0-dev.2) (2025-12-20)
4+
5+
### Bug Fixes
6+
7+
* **ci:** move sync-develop into Release workflow ([74e3240](https://github.com/MyElectricalData/myelectricaldata_new/commit/74e3240fdd84e4cb5b4bc10894396784408c1800))
8+
* **web:** resolve race condition in OfferSelector initial load ([d1fe1db](https://github.com/MyElectricalData/myelectricaldata_new/commit/d1fe1db96fcd460589f4459706bee0c28c042370))
9+
10+
## [1.3.0-dev.1](https://github.com/MyElectricalData/myelectricaldata_new/compare/1.2.0...1.3.0-dev.1) (2025-12-20)
11+
12+
### Features
13+
14+
* **api:** add Slack notifications for new contributions ([4a87243](https://github.com/MyElectricalData/myelectricaldata_new/commit/4a872435d5c019122ed32d9df031583af17d7300))
15+
* **simulator:** add PDF export per offer and calculation explanations ([bdfa4aa](https://github.com/MyElectricalData/myelectricaldata_new/commit/bdfa4aa5ba3a2400af4fc083b4cc38b74c0032dc))
16+
* **workflow:** update sync process to trigger on successful Release workflow ([a2d039b](https://github.com/MyElectricalData/myelectricaldata_new/commit/a2d039b3d552655959c0b7a0ff68a4ad92779b26))
17+
18+
### Bug Fixes
19+
20+
* **api:** fix type annotations in SlackService ([bb055e9](https://github.com/MyElectricalData/myelectricaldata_new/commit/bb055e9296a3426c68a0bbd2dbff0e4383209141))
21+
22+
### Refactoring
23+
24+
* **web:** consolidate info blocks in Simulator page ([1c4d5d5](https://github.com/MyElectricalData/myelectricaldata_new/commit/1c4d5d59e5750ce1279300274811c5f664e93ac0))
25+
26+
## [1.2.1-dev.1](https://github.com/MyElectricalData/myelectricaldata_new/compare/1.2.0...1.2.1-dev.1) (2025-12-20)
27+
28+
### Features
29+
30+
* **api:** add Slack notifications for new contributions ([4a87243](https://github.com/MyElectricalData/myelectricaldata_new/commit/4a872435d5c019122ed32d9df031583af17d7300))
31+
* **simulator:** add PDF export per offer and calculation explanations ([bdfa4aa](https://github.com/MyElectricalData/myelectricaldata_new/commit/bdfa4aa5ba3a2400af4fc083b4cc38b74c0032dc))
32+
* **workflow:** update sync process to trigger on successful Release workflow ([a2d039b](https://github.com/MyElectricalData/myelectricaldata_new/commit/a2d039b3d552655959c0b7a0ff68a4ad92779b26))
33+
34+
### Bug Fixes
35+
36+
* **api:** fix type annotations in SlackService ([bb055e9](https://github.com/MyElectricalData/myelectricaldata_new/commit/bb055e9296a3426c68a0bbd2dbff0e4383209141))
37+
38+
### Refactoring
39+
40+
* **web:** consolidate info blocks in Simulator page ([1c4d5d5](https://github.com/MyElectricalData/myelectricaldata_new/commit/1c4d5d59e5750ce1279300274811c5f664e93ac0))
41+
342
## [1.2.0](https://github.com/MyElectricalData/myelectricaldata_new/compare/1.1.0...1.2.0) (2025-12-20)
443

544
### Features

apps/api/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "myelectricaldata-api"
3-
version = "1.2.0"
3+
version = "1.3.0-dev.2"
44
description = "MyElectricalData API Gateway for Enedis data"
55
authors = [{name = "m4dm4rtig4n"}]
66
license = {text = "Apache-2.0"}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#!/usr/bin/env python3
2+
"""
3+
Script de test pour les notifications Slack
4+
5+
Usage:
6+
python scripts/test_slack_notification.py
7+
8+
Configuration:
9+
Définir SLACK_WEBHOOK_URL et SLACK_NOTIFICATIONS_ENABLED=true dans .env
10+
"""
11+
12+
import asyncio
13+
import sys
14+
from pathlib import Path
15+
16+
# Add src to path
17+
sys.path.insert(0, str(Path(__file__).parent.parent / "src"))
18+
19+
from services.slack import slack_service
20+
from models.energy_provider import OfferContribution
21+
from models.user import User
22+
from unittest.mock import MagicMock
23+
24+
25+
async def test_notification():
26+
"""Test sending a Slack notification"""
27+
print("Testing Slack notification service...")
28+
print(f"Enabled: {slack_service.enabled}")
29+
print(f"Webhook URL configured: {bool(slack_service.webhook_url)}")
30+
31+
if not slack_service.enabled:
32+
print("\n⚠️ Slack notifications are disabled.")
33+
print("Set SLACK_NOTIFICATIONS_ENABLED=true in .env to enable.")
34+
return
35+
36+
if not slack_service.webhook_url:
37+
print("\n⚠️ Slack webhook URL is not configured.")
38+
print("Set SLACK_WEBHOOK_URL in .env with your webhook URL.")
39+
return
40+
41+
# Create mock objects
42+
print("\nCreating mock contribution and user...")
43+
44+
user = MagicMock(spec=User)
45+
user.id = "test-user-123"
46+
user.email = "[email protected]"
47+
48+
contribution = MagicMock(spec=OfferContribution)
49+
contribution.id = "test-contrib-456"
50+
contribution.contribution_type = "NEW_OFFER"
51+
contribution.offer_name = "Test Offer - EDF Tempo 2025"
52+
contribution.offer_type = "TEMPO"
53+
contribution.provider_name = "EDF"
54+
contribution.power_kva = 6
55+
contribution.pricing_data = {
56+
"subscription_price": 12.50,
57+
"tempo_blue_hc": 0.12340,
58+
"tempo_blue_hp": 0.23450,
59+
"tempo_white_hc": 0.34560,
60+
"tempo_white_hp": 0.45670,
61+
"tempo_red_hc": 0.56780,
62+
"tempo_red_hp": 0.67890,
63+
}
64+
contribution.price_sheet_url = "https://example.com/edf-tempo-2025.pdf"
65+
66+
print("\nSending notification to Slack...")
67+
result = await slack_service.send_contribution_notification(contribution, user)
68+
69+
if result:
70+
print("✅ Notification sent successfully!")
71+
else:
72+
print("❌ Failed to send notification. Check logs for details.")
73+
74+
75+
if __name__ == "__main__":
76+
asyncio.run(test_notification())

apps/api/src/config/settings.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ def database_type(self) -> str:
6666
# Admin
6767
ADMIN_EMAILS: str = ""
6868

69+
# Slack Notifications
70+
SLACK_WEBHOOK_URL: str = ""
71+
SLACK_NOTIFICATIONS_ENABLED: bool = False
72+
6973
def is_admin(self, email: str) -> bool:
7074
"""Check if an email is in the admin list"""
7175
if not self.ADMIN_EMAILS:

apps/api/src/routers/energy_offers.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from ..schemas import APIResponse, ErrorDetail
88
from ..middleware import get_current_user, require_permission, require_action, require_not_demo
99
from ..services.email import email_service
10+
from ..services.slack import slack_service
1011
from ..config import settings
1112
import logging
1213

@@ -156,6 +157,13 @@ async def create_contribution(
156157
logger.error(f"[CONTRIBUTION] Failed to send admin notifications: {str(e)}")
157158
# Don't fail the contribution if email fails
158159

160+
# Send Slack notification (fire-and-forget, don't block on errors)
161+
try:
162+
await slack_service.send_contribution_notification(contribution, current_user)
163+
except Exception as e:
164+
logger.error(f"[CONTRIBUTION] Failed to send Slack notification: {str(e)}")
165+
# Don't fail the contribution if Slack fails
166+
159167
return APIResponse(
160168
success=True,
161169
data={

apps/api/src/services/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from .cache import cache_service
22
from .email import email_service
33
from .rate_limiter import rate_limiter
4+
from .slack import slack_service
45

5-
__all__ = ["cache_service", "email_service", "rate_limiter"]
6+
__all__ = ["cache_service", "email_service", "rate_limiter", "slack_service"]

0 commit comments

Comments
 (0)