git-webhook/app.py

23 lines
626 B
Python
Raw Normal View History

2023-05-26 02:00:06 +02:00
from flask import Flask, request
import subprocess
import json
app = Flask(__name__)
@app.route('/webhook', methods=['POST'])
def webhook():
# Check if the received webhook is from Git
if request.headers.get('X-GitHub-Event') == 'push':
# Pull the latest changes from Git
subprocess.run(['git', 'pull'])
# Restart the example_app
subprocess.run(['systemctl', 'restart', 'restart_this_app.service'])
2023-05-26 02:00:06 +02:00
return 'Success!', 200
else:
return 'Invalid webhook event.', 400
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5001)