From 43f9b9fb04390da49bdb78be7d4b224d53b8ea6f Mon Sep 17 00:00:00 2001 From: plenoir Date: Sat, 11 Apr 2026 20:04:32 +0200 Subject: [PATCH 1/3] webhookdemo -> webhookgitlabdemo --- gitpull.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/gitpull.py b/gitpull.py index 221781c..318faf6 100644 --- a/gitpull.py +++ b/gitpull.py @@ -14,7 +14,7 @@ @app.get("/", response_class=HTMLResponse) async def home(): - # Page HTML simple avec un lien vers /webhookdemo + # Page HTML simple avec un lien vers /webhookgitlabdemo html_content = """ @@ -24,7 +24,7 @@ async def home():

Bienvenue sur le serveur de webhook GitHub

Cliquez ci-dessous pour tester le webhook :

- Tester le webhook + Tester le webhook """ @@ -50,8 +50,8 @@ def webhook(request: Request): return "Ignoré : ce n'est pas un push sur la branche principale.", 200 -@app.get('/webhookdemo') -def webhookdemo(): +@app.get('/webhookgitlabdemo') +def webhookgitlabdemo(): # Vérifier la signature (optionnel) import json with(open('demo/demo.json', 'r')) as openjson: From bed91889e2d3cf33b4dfd2b5ac5011cd9db16c5a Mon Sep 17 00:00:00 2001 From: plenoir Date: Sat, 11 Apr 2026 22:14:31 +0200 Subject: [PATCH 2/3] =?UTF-8?q?#11=20ajouter=20nohup=20=C3=A0=20.gitignore?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + gitpull.py | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 1c06c63..6ba5422 100644 --- a/.gitignore +++ b/.gitignore @@ -209,3 +209,4 @@ __marimo__/ demo/demo.json config.json /.idea/ +nohup.out diff --git a/gitpull.py b/gitpull.py index 318faf6..221781c 100644 --- a/gitpull.py +++ b/gitpull.py @@ -14,7 +14,7 @@ @app.get("/", response_class=HTMLResponse) async def home(): - # Page HTML simple avec un lien vers /webhookgitlabdemo + # Page HTML simple avec un lien vers /webhookdemo html_content = """ @@ -24,7 +24,7 @@ async def home():

Bienvenue sur le serveur de webhook GitHub

Cliquez ci-dessous pour tester le webhook :

- Tester le webhook + Tester le webhook """ @@ -50,8 +50,8 @@ def webhook(request: Request): return "Ignoré : ce n'est pas un push sur la branche principale.", 200 -@app.get('/webhookgitlabdemo') -def webhookgitlabdemo(): +@app.get('/webhookdemo') +def webhookdemo(): # Vérifier la signature (optionnel) import json with(open('demo/demo.json', 'r')) as openjson: From 2d37362f2d3fa29b25c85928a069222db414addd Mon Sep 17 00:00:00 2001 From: plenoir Date: Sat, 11 Apr 2026 22:41:47 +0200 Subject: [PATCH 3/3] #10 Avoir un beats pour valider le bon fonctionnement de l'API --- gitpull.py | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/gitpull.py b/gitpull.py index 221781c..516ab1b 100644 --- a/gitpull.py +++ b/gitpull.py @@ -11,7 +11,6 @@ with(open('config/config.json', 'r')) as githubjson: config_github = json.load(githubjson) - @app.get("/", response_class=HTMLResponse) async def home(): # Page HTML simple avec un lien vers /webhookdemo @@ -30,6 +29,9 @@ async def home(): """ return HTMLResponse(content=html_content, status_code=200) +@app.get('/beats') +def beats(): + return {"result": True}, 200 @app.post('/webhook') def webhook(request: Request): @@ -57,7 +59,7 @@ def webhookdemo(): with(open('demo/demo.json', 'r')) as openjson: webhook_github = json.load(openjson) - return update_webhook(webhook_github) + return update_webhook(webhook_github), 200 def update_webhook(webhook_github): @@ -65,14 +67,40 @@ def update_webhook(webhook_github): repo = webhook_github['repository']['full_name'] path_repo = config_github[repo]['path'] command = ['git', '-C', path_repo, 'pull'] + result = True + message = f"repo mis à jour dans {path_repo} avec la commande : {command}" if os.path.isdir(path_repo): print("Retour en arrière") command_reset = ['git', 'reset', '--hard', 'HEAD~1'] subprocess.run(command_reset) print("Mise à jour du dépot") - subprocess.run(command) - return f"repo mis à jour dans {path_repo} avec la commande : {command}" + retour_git = subprocess.run(command, + stdout=subprocess.PIPE, # Capturer la sortie standard + stderr=subprocess.PIPE, # Capturer la sortie d'erreur + text=True, # Retourner les sorties sous forme de chaînes de caractères + ) + + # Vérifier le code de retour + if retour_git.returncode == 0: + print("La commande a réussi.") + print(f"Sortie standard : {retour_git.stdout}") + message = retour_git.stdout # Message de retour en cas de succès + result = True + else: + print(f"La commande a échoué avec le code {retour_git.returncode}.") + print(f"Sortie d'erreur : {retour_git.stderr}") + message = retour_git.stderr # Message d'erreur + result = False + + retour = { + "result": result, + "message": message + } + + # retour vers home assistant + + return retour except Exception as ex: return ex