githubapp.webhook_handler

Module to helps handle the Github webhooks events

Module Contents

Functions

add_handler

Decorator to register a method as a webhook handler.

default_index

Decorator to register a default root handler.

handle

Handle a webhook request.

handle_with_flask

This function registers the webhook_handler with a Flask application.

register_method_for_event

Add a handler for a specific event type.

Data

handlers

API

exception githubapp.webhook_handler.SignatureError(method: collections.abc.Callable[[Any], Any], signature: str)

Bases: Exception

Exception when the method has a wrong signature

Initialization

Args: method (Callable): The method to be validated. signature (str): The signature of the method.

githubapp.webhook_handler.add_handler(event: type[githubapp.events.event.Event]) collections.abc.Callable[[collections.abc.Callable[[githubapp.events.event.Event], None]], collections.abc.Callable]

Decorator to register a method as a webhook handler.

Args: event (type[Event]): The Event subclass to handle.

Returns: Callable: A decorator that validates the handler signature.

githubapp.webhook_handler.default_index(name: str, version: str = None, versions_to_show: Optional[list[str]] = None) collections.abc.Callable[[], str]

Decorator to register a default root handler.

Args: name (str): The name of the App. version (str): The version of the App. versions_to_show (Optional[list]): The libraries to show the version.

githubapp.webhook_handler.handle(headers: dict[str, Any], body: dict[str, Any], config_file: str = None) None

Handle a webhook request.

The request headers and body are passed to the appropriate handler methods.

Args: headers (dict): The request headers. body (dict): The request body. config_file (str): The path to the configuration file.

githubapp.webhook_handler.handle_with_flask(app: flask.Flask, use_default_index: bool = True, webhook_endpoint: str = '/', auth_callback_handler: Optional[collections.abc.Callable[[int, github.AccessToken.AccessToken], None]] = None, version: str = None, versions_to_show: list[str] = None, config_file: str = None) None

This function registers the webhook_handler with a Flask application.

Args: app (Flask): The Flask application to register the webhook_handler with. use_default_index (bool): Whether to register the root handler with the Flask application. Default is False. webhook_endpoint (str): The endpoint to register the webhook_handler with. Default is “/”. auth_callback_handler (Callable[[int, AccessToken], None]): The function to handle the auth_callback. Default is None.

version (str): The version of the App.
versions_to_show (str): The libraries to show the version.
config_file (str): The config file path to autoload

Returns: None

Raises: TypeError: If the app parameter is not a Flask instance.

githubapp.webhook_handler.handlers

‘defaultdict(…)’

githubapp.webhook_handler.register_method_for_event(event: type[githubapp.events.event.Event], handler: collections.abc.Callable[[githubapp.events.event.Event], None]) None

Add a handler for a specific event type.

The handler must accept only one argument of the Event type.

Args: event (type[Event]): The event type to handle. handler (Callable): The handler method.