gitWebhook Module

Python module providing Flask blueprints for handling various git app wehbooks.

class gitWebhook.functionWebhookBlueprint(webhookToken: str | None, functions: list[Callable[[dict[str, Any]], bool | Any]], log: Logger | None = None, name: str = 'webhook', github: bool = True, gitlab: bool = True, gitea: bool = True, ipWhitelist: list[str] | None = None, *args, **kwargs)

Bases: webhookBlueprint

A subclass of webhookBlueprint that processes the webhook data using a list of functions. The functions should return True if the webhook data is valid, and False otherwise. If the function returns a string, it will be included in the output.

processWebhook(data: dict[str, Any]) tuple[int, str][source]

Process the webhook data using the list of functions. If any function returns False, the process will return a 400 status code. If any function returns an invalid type, the process will return a 500 status code. Otherwise, the process will return a 200 status code. All function outputs are returned to git as a string.

Parameters:

data (dict[str, Any]) – The webhook data.

Returns:

The status code and message.

Return type:

tuple[int, str]

class gitWebhook.gitWebhookBlueprintABC(webhookToken: str | None, name: str = 'webhook', *args, **kwargs)

Bases: ABC

An abstract class for a webhook blueprint that processes git webhooks.

abstract processWebhook(data: dict[str, Any]) tuple[int, str][source]

Process the webhook data and return a status code and message.

Parameters:

data (dict[str, Any]) – The webhook data.

Returns:

The status code and message.

Return type:

tuple[int, str]

abstract receiveWebhook() Response[source]

Method that acts as a POST endpoint for the webhook blueprint.

Returns:

The response to the webhook request.

Return type:

Response

class gitWebhook.pullerWebhookBlueprint(webhookToken: str | None, tests: TestSuite | None = None, log: Logger | None = None, name: str = 'webhook', github: bool = True, gitlab: bool = True, gitea: bool = True, ipWhitelist: list[str] | None = None, gitCommand: str = '/usr/bin/git', commandEnv: dict[str, str] | None = None, *args, **kwargs)

Bases: webhookBlueprint

A subclass of webhookBlueprint that processes the webhook data by pulling from a git repository and running tests.

processWebhook(data: dict[str, Any]) tuple[int, str][source]

Process the webhook data by pulling from a git repository and running tests. If the tests are not provided, only the pull will be done. Otherwise the tests will be ran and if they fail the merge will be aborted.

Parameters:

data (dict[str, Any]) – The webhook data.

Returns:

The status code and message.

Return type:

tuple[int, str]

class gitWebhook.webhookBlueprint(webhookToken: str | None, log: Logger | None = None, name: str = 'webhook', github: bool = True, gitlab: bool = True, gitea: bool = True, ipWhitelist: list[str] | None = None, *args, **kwargs)

Bases: Blueprint, gitWebhookBlueprintABC

Wrapper over the flask blueprint that creates an endpoint for receiving and processing git webhooks. Overwrite the processWebhook method to process the webhook data.

hook(func: Callable[[...], Any]) Callable[[...], Any][source]

Adds a function to the list of functions that will be called when a webhook is received. This is different from what functionWebhook functions do as this function is called before the processWebhook method and the return value is not checked.

Parameters:

func (Callable) – The function to add to the list of functions that will be called when a webhook is received.

processWebhook(data: dict[str, Any]) tuple[int, str][source]

Process the webhook. Return a tuple of (status code, message)

Parameters:

data (dict[str, Any]) – The webhook data

Returns:

HTTP return code with a message

Return type:

tuple[int, str]

receiveWebhook() Response[source]

Method that acts as a POST endpoint for the webhook blueprint.

Returns:

The response to the webhook request.

Return type:

Response