-
Notifications
You must be signed in to change notification settings - Fork 0
/
webhook.py
32 lines (24 loc) · 1018 Bytes
/
webhook.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from flask import Flask, request
import subprocess
import logging
app = Flask(__name__)
# Configure logging
logging.basicConfig(level=logging.INFO)
@app.route('/github-webhook', methods=['POST'])
def webhook():
try:
# Log headers and payload for debugging
logging.info('Received headers: %s', request.headers)
logging.info('Received payload: %s', request.get_data())
# Update the path to your shell script
script_path = './deployment.sh'
# Execute the shell script
result = subprocess.run(['bash', script_path], capture_output=True, text=True)
# Log the result of the shell script execution
logging.info('Shell script execution result:\n%s', result.stdout)
return 'Webhook received and script executed successfully', 200
except Exception as e:
logging.error(f'Error during webhook processing: {str(e)}')
return 'Internal server error', 500
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000)