V1.4 de l'amélioration du suivi des issues

This commit is contained in:
Mathis 2026-07-12 18:41:25 +02:00
parent f26ff968f3
commit c14e2fb7e3
6 changed files with 47 additions and 62 deletions

View file

@ -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}")
# 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'ancien fichier
# 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)