Python library that makes bitbucket webhook API event payloads available via decorators with payload serialized into python objects.
$ pip install bitbucket-webhooks
from flask import Flask
from flask import request
from bitbucket_webhooks import event_schemas
from bitbucket_webhooks import hooks
from bitbucket_webhooks import router
app = Flask(__name__)
@app.route("/hooks", methods=["POST"])
def bb_webhooks_handler():
router.route(request.headers["X-Event-Key"], request.json)
return ("", 204)
@hooks.repo_push
def _handle_repo_push(event: event_schemas.RepoPush):
print(f"One or more commits pushed to: {event.repository.name}"
Here is the full example.
- repo:push
- pullrequest:created
- pullrequest:updated
- pullrequest:approved
- pullrequest:unapproved
- pullrequest:fulfilled
- pullrequest:rejected
- pullrequest:comment_created
- pullrequest:comment_updated
- pullrequest:comment_deleted