627 shaares
1 result
tagged
flask
Un webhook listener en Python avec Flask pour exécuter des actions automatiquement après un push git sur GitHub ou BitBucket:
import os
from sys import platform as _platform
from flask import Flask
from flask import request
app = Flask(__name__)
@app.route('/webhook', methods=['POST'])
def tracking():
data = request.get_json()
commit_author = data['actor']['username']
commit_hash = data['push']['changes'][0]['old']['target']['hash'][:7]
commit_url = data['push']['changes'][0]['old']['target']['links']['html']['href']
print 'Webhook received! %s committed %s: %s' % (commit_author, commit_hash, commit_url)
return 'OK'
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000, debug=True)