Skip to content

Instantly share code, notes, and snippets.

@itbrunoms
Created October 31, 2024 15:25
Show Gist options
  • Select an option

  • Save itbrunoms/d38c67540dfbaf2633036d8a696d002c to your computer and use it in GitHub Desktop.

Select an option

Save itbrunoms/d38c67540dfbaf2633036d8a696d002c to your computer and use it in GitHub Desktop.

Revisions

  1. itbrunoms created this gist Oct 31, 2024.
    33 changes: 33 additions & 0 deletions gistfile1.txt
    Original 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)