Created
October 31, 2024 15:25
-
-
Save itbrunoms/d38c67540dfbaf2633036d8a696d002c to your computer and use it in GitHub Desktop.
Revisions
-
itbrunoms created this gist
Oct 31, 2024 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,33 @@ 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)