Fix: récupération des issues_gitlab après incident
This commit is contained in:
parent
ed6e25c219
commit
b6d2995916
8 changed files with 682 additions and 308 deletions
77
scripts/migrate_gitlab_tracking.py
Normal file
77
scripts/migrate_gitlab_tracking.py
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
#!/usr/bin/env python3
|
||||
"""
|
||||
Script de migration automatique pour fusionner gitlab_reports.json dans gitlab_issues.json.
|
||||
|
||||
Ce script est conçu pour être appelé AUTOMATIQUEMENT lors du déploiement.
|
||||
Il garantit que toutes les issues sont suivies dans un seul fichier.
|
||||
|
||||
Usage:
|
||||
python scripts/migrate_gitlab_tracking.py
|
||||
"""
|
||||
|
||||
import os
|
||||
import json
|
||||
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")
|
||||
LEGACY_REPORTS_FILE = os.path.join(BASE_DIR, "data", "gitlab_reports.json")
|
||||
|
||||
|
||||
def migrate_tracking():
|
||||
"""Fusionne gitlab_reports.json dans gitlab_issues.json"""
|
||||
print("🔄 Début de la migration GitLab tracking...")
|
||||
|
||||
# Charge le fichier principal
|
||||
tracking = {}
|
||||
if os.path.exists(TRACKING_FILE):
|
||||
try:
|
||||
with open(TRACKING_FILE, "r", encoding="utf-8") as f:
|
||||
tracking = json.load(f)
|
||||
print(f"✅ Chargé {len(tracking)} issues depuis gitlab_issues.json")
|
||||
except Exception as e:
|
||||
print(f"⚠️ Erreur chargement gitlab_issues.json: {e}")
|
||||
|
||||
# Fusionne avec l'ancien fichier
|
||||
migrated_count = 0
|
||||
if os.path.exists(LEGACY_REPORTS_FILE):
|
||||
try:
|
||||
with open(LEGACY_REPORTS_FILE, "r", encoding="utf-8") as f:
|
||||
legacy_data = json.load(f)
|
||||
|
||||
for issue_iid, user_id in legacy_data.items():
|
||||
if issue_iid not in tracking:
|
||||
tracking[issue_iid] = {
|
||||
"requester_id": user_id,
|
||||
"last_note_id": 0,
|
||||
"type": "legacy_report"
|
||||
}
|
||||
migrated_count += 1
|
||||
|
||||
print(f"✅ Migration: {migrated_count} issues fusionnées depuis gitlab_reports.json")
|
||||
except Exception as e:
|
||||
print(f"⚠️ Erreur migration gitlab_reports.json: {e}")
|
||||
|
||||
# Sauvegarde le résultat
|
||||
if tracking:
|
||||
os.makedirs(os.path.dirname(TRACKING_FILE), exist_ok=True)
|
||||
temp_file = f"{TRACKING_FILE}.tmp"
|
||||
with open(temp_file, "w", encoding="utf-8") as f:
|
||||
json.dump(tracking, f, ensure_ascii=False, indent=2)
|
||||
os.replace(temp_file, TRACKING_FILE)
|
||||
print(f"✅ Sauvegardé {len(tracking)} issues dans gitlab_issues.json")
|
||||
|
||||
print("✅ Migration terminée avec succès !")
|
||||
return migrated_count
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
migrated = migrate_tracking()
|
||||
|
||||
# Si des données ont été migrées, on peut optionnellement nettoyer l'ancien fichier
|
||||
if migrated > 0:
|
||||
print(f"\n💡 {migrated} issues ont été migrées depuis gitlab_reports.json")
|
||||
print("💡 Tu peux maintenant supprimer data/gitlab_reports.json si tu veux.")
|
||||
|
||||
sys.exit(0)
|
||||
Loading…
Add table
Add a link
Reference in a new issue