API Documentation
github_bot_api
Event
dataclass
Represents a GitHub webhook event.
Source code in github_bot_api/event.py
signature
instance-attribute
The signature of the event. Will only be set if a Webhook-secret is configured on the
client side (e.g. in Webhook.secret
/ if the webhook_secret parameter is
passed to accept_event()
).
GithubApp
dataclass
Represents a GitHub application and all the required details.
Source code in github_bot_api/app.py
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
|
jwt
property
Returns the JWT for your GitHub application. The JWT is the token to use with GitHub application APIs.
jwt_supplier
property
Returns a new #JwtSupplier that is used for generating JWT tokens for your GitHub application.
user_agent
instance-attribute
User agent of the application. This will be respected in #get_user_agent().
v3_api_url
class-attribute
instance-attribute
GitHub API base URL. Defaults to the public GitHub API.
app_client
Returns a PyGithub client for your GitHub application.
Note that the client's token will expire after 10 minutes and you will have to create a new client or update the client's token with the value returned by #jwt. It is recommended that you create a new client for each atomic operation you perform.
This requires you to install PyGithub>=1.58
.
Source code in github_bot_api/app.py
get_installation_token_supplier
Create an #InstallationTokenSupplier for your GitHub application to act within the scope of the given installation_id.
Source code in github_bot_api/app.py
get_user_agent
Create a user agent string for the PyGithub client, including the installation if specified.
Source code in github_bot_api/app.py
installation_client
installation_client(
installation_id: int,
settings: Union[
GithubClientSettings, Dict[str, Any], None
] = None,
) -> Github
Returns a PyGithub client for your GitHub application to act in the scope of the given installation_id.
Note that the client's token will expire after 10 minutes and you will have to create a new client or update the client's token with the value returned by #jwt. It is recommended that you create a new client for each atomic operation you perform.
This requires you to install PyGithub>=1.58
.
Source code in github_bot_api/app.py
installation_token
A short-hand to retrieve a new installation token for the given installation_id.
Webhook
dataclass
Represents a GitHub webhook that listens on an HTTP endpoint for events. Event handlers can be registered using the #@on() decorator or #register() method.
Source code in github_bot_api/webhook.py
dispatch
dispatch(event: Event) -> bool
Dispatch an event on the first handler that matches it.
Returns #True only if the event was handled by a handler.
Source code in github_bot_api/webhook.py
accept_event
accept_event(
headers: Mapping[str, str],
raw_body: bytes,
webhook_secret: Optional[str] = None,
) -> Event
Converts thee HTTP headers and the raw_body to an #Event object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
headers |
Mapping[str, str]
|
The HTTP headers. Must have |
required |
raw_body |
bytes
|
The raw request body for the event. This is converted into a JSON payload. |
required |
webhook_secret |
Optional[str]
|
If specified, the |
None
|
Source code in github_bot_api/event.py
github_bot_api.flask
Flask binding for handling GitHub webhook events.
Note that you need to install the flask
module separately.
Example
from github_bot_api import Event, Webhook
from github_bot_api.flask import create_flask_app
def on_any_event(event: Event) -> bool:
print(event)
return True
webhook = Webhook(secret=None)
webhook.listen('*', on_any_event)
import os; os.environ['FLASK_ENV'] = 'development'
flask_app = create_flask_app(__name__, webhook)
flask_app.run()
create_event_handler
create_event_handler(
webhook: Webhook,
) -> Callable[[], Tuple[Text, int, Dict[str, str]]]
Creates an event handler flask view that interprets the received HTTP request as a GitHub application event and dispatches it via #webhook.dispatch().
Source code in github_bot_api/flask.py
create_flask_app
create_flask_app(
name: str,
webhook: Webhook,
path: str = "/event-handler",
) -> Flask
Creates a new #flask.Flask application with a POST
event handler under the given path (defaulting
to /event-handler
). This is a useful shorthand to attach your #Webhook to an HTTP server.