Created
October 31, 2024 15:25
-
-
Save itbrunoms/d38c67540dfbaf2633036d8a696d002c to your computer and use it in GitHub Desktop.
webook for update code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
from flask import Flask, request, jsonify | |
import subprocess | |
app = Flask(__name__) | |
@app.route('/webhook', methods=['POST']) | |
def webhook(): | |
data = request.get_json() | |
value_to_check = "[nome_da_branc]" | |
if value_to_check in data['ref']: | |
project_path = '[pasta_do_projeto]' | |
os.chdir(project_path) | |
try: | |
#result = subprocess.check_output(['git', 'pull']) | |
os.system('git pull') | |
os.system('docker exec api_php php artisan migrate') | |
return jsonify({'status': 'success', 'message': 'Git pull executado com sucesso.'}) | |
except Exception as e: | |
response = jsonify({'status': 'error', 'message': str(e)}) | |
response.status_code = 500 # Defina o código de status HTTP para 500 (Erro interno do servidor) | |
response.headers['X-Error-Message'] = 'Ocorreu um erro interno no servidor.' | |
return response | |
else: | |
response = jsonify({'status': 'error', 'message': 'Branche nao encontrada, abortando'}) | |
response.status_code = 200 | |
response.headers['X-Error-Message'] = 'Branche nao encontada' | |
return response | |
if __name__ == '__main__': | |
app.run(host='0.0.0.0', port=8001) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment