V1.4 de l'amélioration du suivi des issues
This commit is contained in:
parent
f26ff968f3
commit
c14e2fb7e3
6 changed files with 47 additions and 62 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
|
@ -13,6 +13,9 @@ config.db
|
|||
*.db-journal
|
||||
*.db-wal
|
||||
*.db-shm
|
||||
*gitlab_issues.json
|
||||
*forgejo_issues.json
|
||||
|
||||
|
||||
# Dossiers de stockage
|
||||
data/
|
||||
|
|
|
|||
|
|
@ -13,14 +13,10 @@ from utils.premium import check_premium_tier
|
|||
kuby_logger = logging.getLogger("KubyBot")
|
||||
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
PROJECT_ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir))
|
||||
TRACKING_FILE = os.path.join(PROJECT_ROOT, "commandes", "gitlab_issues.json")
|
||||
TRACKING_FILE = os.path.join(PROJECT_ROOT, "data", "gitlab_issues.json")
|
||||
LEGACY_REPORTS_FILE = os.path.join(PROJECT_ROOT, "data", "gitlab_reports.json")
|
||||
LEGACY_TRACKING_FILE = os.path.join(PROJECT_ROOT, "commandes", "gitlab_issues.json")
|
||||
|
||||
# S'assure que le fichier de tracking est toujours écrit à l'emplacement attendu même si le service systemd démarre depuis un autre répertoire.
|
||||
if not os.path.exists(TRACKING_FILE):
|
||||
legacy_candidate = os.path.join(BASE_DIR, "commandes", "gitlab_issues.json")
|
||||
if os.path.exists(legacy_candidate):
|
||||
TRACKING_FILE = legacy_candidate
|
||||
|
||||
|
||||
def classify_webhook_event(payload: Dict[str, Any]) -> Optional[str]:
|
||||
|
|
@ -268,14 +264,27 @@ def extract_requester_id_from_payload(payload: Dict[str, Any]) -> Optional[int]:
|
|||
def load_tracking():
|
||||
"""Charge le tracking depuis gitlab_issues.json (avec migration automatique)"""
|
||||
tracking = {}
|
||||
|
||||
# 1. Tenter de charger depuis la nouvelle localisation dans data/
|
||||
if os.path.exists(TRACKING_FILE):
|
||||
try:
|
||||
with open(TRACKING_FILE, "r", encoding="utf-8") as f:
|
||||
tracking = json.load(f)
|
||||
except Exception as e:
|
||||
kuby_logger.error(f"Erreur chargement gitlab_issues.json: {e}")
|
||||
kuby_logger.error(f"Erreur chargement gitlab_issues.json dans data/: {e}")
|
||||
|
||||
# Migration automatique depuis l'ancien fichier
|
||||
# 2. Si non trouvé, tenter de charger depuis l'ancienne localisation dans commandes/ (migration)
|
||||
if not tracking and os.path.exists(LEGACY_TRACKING_FILE):
|
||||
try:
|
||||
with open(LEGACY_TRACKING_FILE, "r", encoding="utf-8") as f:
|
||||
tracking = json.load(f)
|
||||
kuby_logger.info(f"Migration: Chargé l'ancien fichier de tracking depuis {LEGACY_TRACKING_FILE}")
|
||||
# Sauvegarder immédiatement dans le nouvel emplacement
|
||||
save_tracking(tracking)
|
||||
except Exception as e:
|
||||
kuby_logger.error(f"Erreur chargement ancien gitlab_issues.json dans commandes/: {e}")
|
||||
|
||||
# Migration automatique depuis l'historique gitlab_reports.json
|
||||
if os.path.exists(LEGACY_REPORTS_FILE):
|
||||
try:
|
||||
with open(LEGACY_REPORTS_FILE, "r", encoding="utf-8") as f:
|
||||
|
|
@ -296,13 +305,16 @@ def load_tracking():
|
|||
}
|
||||
migrated_count += 1
|
||||
|
||||
kuby_logger.info(f"Migration automatique: {migrated_count} issue(s) fusionnée(s) depuis l'historique")
|
||||
if migrated_count > 0:
|
||||
kuby_logger.info(f"Migration automatique: {migrated_count} issue(s) fusionnée(s) depuis l'historique")
|
||||
save_tracking(tracking)
|
||||
except Exception as e:
|
||||
kuby_logger.error(f"Erreur migration gitlab_reports.json: {e}")
|
||||
|
||||
return tracking
|
||||
|
||||
|
||||
|
||||
def save_tracking(data: Dict[str, Any]) -> None:
|
||||
"""Sauvegarde dans gitlab_issues.json"""
|
||||
os.makedirs(os.path.dirname(TRACKING_FILE), exist_ok=True)
|
||||
|
|
|
|||
|
|
@ -18,7 +18,9 @@ if not FORGEJO_TOKEN or not FORGEJO_OWNER or not FORGEJO_REPO:
|
|||
raise RuntimeError("Forgejo variables (FORGEJO_TOKEN, FORGEJO_OWNER, FORGEJO_REPO) must be set.")
|
||||
|
||||
# Fichiers de persistance mis à jour pour Forgejo
|
||||
ISSUE_TRACK_FILE = os.path.join(os.path.dirname(__file__), "forgejo_issues.json")
|
||||
PROJECT_ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir))
|
||||
ISSUE_TRACK_FILE = os.path.join(PROJECT_ROOT, "data", "forgejo_issues.json")
|
||||
LEGACY_ISSUE_TRACK_FILE = os.path.join(PROJECT_ROOT, "commandes", "forgejo_issues.json")
|
||||
|
||||
def load_issue_tracking() -> Dict[str, Any]:
|
||||
tracking = {}
|
||||
|
|
@ -27,12 +29,26 @@ def load_issue_tracking() -> Dict[str, Any]:
|
|||
with open(ISSUE_TRACK_FILE, "r", encoding="utf-8") as f:
|
||||
tracking = json.load(f)
|
||||
except Exception as e:
|
||||
print(f"⚠️ Erreur chargement forgejo_issues.json: {e}")
|
||||
print(f"⚠️ Erreur chargement forgejo_issues.json dans data/: {e}")
|
||||
|
||||
if not tracking and os.path.exists(LEGACY_ISSUE_TRACK_FILE):
|
||||
try:
|
||||
with open(LEGACY_ISSUE_TRACK_FILE, "r", encoding="utf-8") as f:
|
||||
tracking = json.load(f)
|
||||
print(f"Migration: Chargé forgejo_issues.json depuis {LEGACY_ISSUE_TRACK_FILE}")
|
||||
save_issue_tracking(tracking)
|
||||
except Exception as e:
|
||||
print(f"⚠️ Erreur chargement ancien forgejo_issues.json: {e}")
|
||||
|
||||
return tracking
|
||||
|
||||
def save_issue_tracking(data: Dict[str, Any]) -> None:
|
||||
with open(ISSUE_TRACK_FILE, "w", encoding="utf-8") as f:
|
||||
os.makedirs(os.path.dirname(ISSUE_TRACK_FILE), exist_ok=True)
|
||||
temp_file = f"{ISSUE_TRACK_FILE}.tmp"
|
||||
with open(temp_file, "w", encoding="utf-8") as f:
|
||||
json.dump(data, f, ensure_ascii=False, indent=2)
|
||||
os.replace(temp_file, ISSUE_TRACK_FILE)
|
||||
|
||||
|
||||
class ForgejoIntegration(commands.Cog):
|
||||
"""Cog fournissant des commandes slash pour créer des tickets sur Forgejo et notifier les utilisateurs."""
|
||||
|
|
|
|||
|
|
@ -1,47 +0,0 @@
|
|||
{
|
||||
"4": {
|
||||
"requester_id": 971446412690722826,
|
||||
"last_note_id": 0,
|
||||
"type": "legacy_report"
|
||||
},
|
||||
"5": {
|
||||
"requester_id": 971446412690722826,
|
||||
"last_note_id": 0,
|
||||
"type": "legacy_report"
|
||||
},
|
||||
"15": {
|
||||
"requester_id": 971446412690722826,
|
||||
"last_note_id": 0,
|
||||
"type": "legacy_report"
|
||||
},
|
||||
"153": {
|
||||
"requester_id": 534003230435442690,
|
||||
"last_note_id": 0,
|
||||
"type": "legacy_report"
|
||||
},
|
||||
"160": {
|
||||
"requester_id": 971446412690722826,
|
||||
"last_note_id": 0,
|
||||
"type": "legacy_report"
|
||||
},
|
||||
"161": {
|
||||
"requester_id": 971446412690722826,
|
||||
"last_note_id": 0,
|
||||
"type": "legacy_report"
|
||||
},
|
||||
"162": {
|
||||
"requester_id": 971446412690722826,
|
||||
"last_note_id": 0,
|
||||
"type": "legacy_report"
|
||||
},
|
||||
"164": {
|
||||
"requester_id": 971446412690722826,
|
||||
"last_note_id": 0,
|
||||
"type": "legacy_report"
|
||||
},
|
||||
"None": {
|
||||
"requester_id": 971446412690722826,
|
||||
"last_note_id": 0,
|
||||
"type": "manual-report"
|
||||
}
|
||||
}
|
||||
|
|
@ -15,7 +15,7 @@ import sys
|
|||
|
||||
# Chemins des fichiers
|
||||
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
TRACKING_FILE = os.path.join(BASE_DIR, "commandes", "gitlab_issues.json")
|
||||
TRACKING_FILE = os.path.join(BASE_DIR, "data", "gitlab_issues.json")
|
||||
LEGACY_REPORTS_FILE = os.path.join(BASE_DIR, "data", "gitlab_reports.json")
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ from typing import Dict, List, Any, Optional
|
|||
|
||||
# Chemin des fichiers de tracking
|
||||
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
GITLAB_ISSUES_FILE = os.path.join(BASE_DIR, "commandes", "gitlab_issues.json")
|
||||
GITLAB_ISSUES_FILE = os.path.join(BASE_DIR, "data", "gitlab_issues.json")
|
||||
GITLAB_REPORTS_FILE = os.path.join(BASE_DIR, "data", "gitlab_reports.json")
|
||||
|
||||
# Configuration GitLab
|
||||
|
|
@ -231,7 +231,8 @@ async def recover_comments():
|
|||
print("✅ RÉCUPÉRATION TERMINÉE")
|
||||
print("=" * 60)
|
||||
print("\nProchaines étapes:")
|
||||
print("1. Vérifiez le fichier commandes/gitlab_issues.json")
|
||||
print("1. Vérifiez le fichier data/gitlab_issues.json")
|
||||
|
||||
print("2. Redémarrez le bot pour qu'il utilise les nouvelles données")
|
||||
print("3. Les nouveaux commentaires seront désormais suivis correctement")
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue