Skip to main content

Typed event handling for GitHub Webhooks

Project description

Typed event handling for GitHub Webhooks

CI codecov

This library provides types for using GitHub Webhook events in Python, and a class for registering event handlers for each event type.

An example using FastAPI:

from fastapi import FastAPI, Request
from gh_webhooks import GhWebhookEventHandler
from gh_webhooks.types import BranchProtectionRuleCreated

app = FastAPI()
event_handler = GhWebhookEventHandler()

@event_handler.on(BranchProtectionRuleCreated)
async def handle_new_branch_protection_rule(event: BranchProtectionRuleCreated):
    print(event.repository.name)


@app.post("/payload")
async def handle_webhook_payload(request: Request):
    await event_handler.handle_event(request.json())

The types are auto-generated using datamodel-code-generator. A GitHub action maintains these types automatically.

Integration tests are also auto-generated from the example events in the GitHub Webhook events spec docs.

Developing

Install Poetry and poetry install the project

Useful Commands

Note: if Poetry is managing a virtual environment for you, you may need to use poetry run poe instead of poe

  • poe autoformat - Autoformat code
  • poe lint - Lint code
  • poe test - Run tests
  • poe docs - Build docs
  • poe codegen - Generate types

Release

Release a new version by manually running the release action on GitHub with a 'major', 'minor', or 'patch' version bump selected. This will create an push a new semver tag of the format v1.2.3.

Pushing this tag will trigger an action to release a new version of your library to PyPI.

Optionally create a release from this new tag to let users know what changed.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gh-webhooks-0.2.0.tar.gz (27.6 kB view details)

Uploaded Source

Built Distribution

gh_webhooks-0.2.0-py3-none-any.whl (27.1 kB view details)

Uploaded Python 3

File details

Details for the file gh-webhooks-0.2.0.tar.gz.

File metadata

  • Download URL: gh-webhooks-0.2.0.tar.gz
  • Upload date:
  • Size: 27.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.12 CPython/3.9.6 Linux/5.13.0-1025-azure

File hashes

Hashes for gh-webhooks-0.2.0.tar.gz
Algorithm Hash digest
SHA256 ddd941f5104589bdf76b113f6ef82dc32fc9fbd5405a92dfa8b74f1f5704eb8b
MD5 b0cbf7e92ec82ab895f9b2a25b9d7d07
BLAKE2b-256 b56bc48e43173114dbb15ecfffeafb5304eb78ca12cbddb2e38c039c897cb240

See more details on using hashes here.

File details

Details for the file gh_webhooks-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: gh_webhooks-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 27.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.12 CPython/3.9.6 Linux/5.13.0-1025-azure

File hashes

Hashes for gh_webhooks-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f8c845a5d9701860ed0d78ccf18259f94ff5fe7c08d150e636ba32f767ef76a8
MD5 28f41e6d3e6bac5f27bf473607dd7c4c
BLAKE2b-256 c1189eab302026ee2f8d138609cba72c34a260e75f755aa3f0de434fc961eefa

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page