correction de bugs de l'auto-déploiement

This commit is contained in:
Mathis 2026-03-15 12:04:18 +01:00
parent 3d52144ad7
commit 432611d4ee

View file

@ -33,16 +33,16 @@ def send_discord_log(status, message, color, author=None, commit_msg=None):
except Exception as e:
print(f"[!] Erreur envoi Discord : {e}")
def run_mep_logic(author, commit_msg):
def run_mep_logic(author, commit_msg, branch="main"):
start_time = datetime.now()
send_discord_log("EN COURS", "Déploiement lancé sur la machine de guerre...", 3447003, author, commit_msg)
send_discord_log("EN COURS", f"Déploiement branch **{branch}** lancé sur la machine de guerre...", 3447003, author, commit_msg)
try:
os.chdir(PROJECT_PATH)
# 1. GIT
subprocess.run(["git", "fetch", "origin"], check=True)
subprocess.run(["git", "reset", "--hard", "origin/main"], check=True)
subprocess.run(["git", "reset", "--hard", f"origin/{branch}"], check=True)
duration = (datetime.now() - start_time).total_seconds()
msg = f"✅ **Déploiement réussi en {duration:.2f}s**\nLe bot est à jour et redémarré."
@ -70,8 +70,12 @@ def deploy():
author = data['commits'][0].get('author', {}).get('name', 'Inconnu')
commit_msg = data['commits'][0].get('message', 'Pas de message')
# Extraction de la branche
ref = data.get('ref', 'refs/heads/main')
branch = ref.split('/')[-1] if ref else 'main'
# Threading pour répondre vite à GitLab
threading.Thread(target=run_mep_logic, args=(author, commit_msg)).start()
threading.Thread(target=run_mep_logic, args=(author, commit_msg, branch)).start()
return {"status": "accepted"}, 202