github-bot-api 0.5.2__tar.gz → 0.6.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- github_bot_api-0.6.0/PKG-INFO +52 -0
- github_bot_api-0.6.0/README.md +24 -0
- {github_bot_api-0.5.2 → github_bot_api-0.6.0}/pyproject.toml +3 -7
- github_bot_api-0.6.0/src/github_bot_api/__init__.py +8 -0
- {github_bot_api-0.5.2 → github_bot_api-0.6.0}/src/github_bot_api/app.py +5 -32
- {github_bot_api-0.5.2 → github_bot_api-0.6.0}/src/github_bot_api/event.py +14 -14
- {github_bot_api-0.5.2 → github_bot_api-0.6.0}/src/github_bot_api/signature.py +3 -3
- {github_bot_api-0.5.2 → github_bot_api-0.6.0}/src/github_bot_api/token.py +1 -1
- github_bot_api-0.6.0/src/github_bot_api/utils/functions.py +29 -0
- {github_bot_api-0.5.2 → github_bot_api-0.6.0}/src/github_bot_api/webhook.py +1 -4
- github_bot_api-0.5.2/LICENSE.txt +0 -20
- github_bot_api-0.5.2/PKG-INFO +0 -104
- github_bot_api-0.5.2/readme.md +0 -69
- github_bot_api-0.5.2/src/github_bot_api/__init__.py +0 -8
- {github_bot_api-0.5.2 → github_bot_api-0.6.0}/LICENSE +0 -0
- {github_bot_api-0.5.2 → github_bot_api-0.6.0}/src/github_bot_api/app_test.py +0 -0
- {github_bot_api-0.5.2 → github_bot_api-0.6.0}/src/github_bot_api/flask.py +0 -0
- {github_bot_api-0.5.2 → github_bot_api-0.6.0}/src/github_bot_api/py.typed +0 -0
- /github_bot_api-0.5.2/src/github_bot_api/__init__test.py → /github_bot_api-0.6.0/src/github_bot_api/tests/test_import.py +0 -0
- {github_bot_api-0.5.2 → github_bot_api-0.6.0}/src/github_bot_api/utils/__init__.py +0 -0
- {github_bot_api-0.5.2 → github_bot_api-0.6.0}/src/github_bot_api/utils/mime.py +0 -0
- {github_bot_api-0.5.2 → github_bot_api-0.6.0}/src/github_bot_api/utils/types.py +0 -0
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: github-bot-api
|
|
3
|
+
Version: 0.6.0
|
|
4
|
+
Summary: API for creating GitHub bots and webhooks in Python.
|
|
5
|
+
License: MIT
|
|
6
|
+
Author: Niklas Rosenstein
|
|
7
|
+
Author-email: rosensteinniklas@gmail.com
|
|
8
|
+
Requires-Python: >=3.8,<4.0
|
|
9
|
+
Classifier: Intended Audience :: Developers
|
|
10
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Requires-Dist: PyGithub (>=1.58,<2.0)
|
|
18
|
+
Requires-Dist: PyJWT (>=2.6.0,<3.0.0)
|
|
19
|
+
Requires-Dist: cryptography (>=42.0.5,<43.0.0)
|
|
20
|
+
Requires-Dist: flask
|
|
21
|
+
Requires-Dist: requests (>=2.28.2,<3.0.0)
|
|
22
|
+
Requires-Dist: urllib3 (>=1.26.15,<2.0.0)
|
|
23
|
+
Project-URL: Bug Tracker, https://github.com/NiklasRosenstein/python-github-bot-api/issues
|
|
24
|
+
Project-URL: Documentation, https://niklasrosenstein.github.io/python-github-bot-api/
|
|
25
|
+
Project-URL: Repository, https://github.com/NiklasRosenstein/python-github-bot-api
|
|
26
|
+
Description-Content-Type: text/markdown
|
|
27
|
+
|
|
28
|
+
<p align="center"><img src="https://i.imgur.com/5SiDsz8.png"></p>
|
|
29
|
+
<h1 align="center">python-github-bot-api</h1>
|
|
30
|
+
<p align="center">
|
|
31
|
+
<a href="https://pypi.org/project/github-bot-api"><img alt="PyPI - Python Version" src="https://img.shields.io/pypi/pyversions/github-bot-api"></a></p>
|
|
32
|
+
|
|
33
|
+
[PyGithub]: https://pypi.org/project/PyGithub/
|
|
34
|
+
|
|
35
|
+
A thin Python library for creating GitHub bots and webhooks in Python with [PyGithub].
|
|
36
|
+
|
|
37
|
+
```python
|
|
38
|
+
from github import Github
|
|
39
|
+
from github_bot_api import GithubApp
|
|
40
|
+
from pathlib import Path
|
|
41
|
+
|
|
42
|
+
app = GithubApp(
|
|
43
|
+
user_agent='my-bot/0.0.0',
|
|
44
|
+
app_id="67890",
|
|
45
|
+
private_key=Path("app-private.key").read_text(),
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
client: Github = app.installation_client(12345)
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
For more examples, check out the [documentation](https://niklasrosenstein.github.io/python-github-bot-api/).
|
|
52
|
+
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
<p align="center"><img src="https://i.imgur.com/5SiDsz8.png"></p>
|
|
2
|
+
<h1 align="center">python-github-bot-api</h1>
|
|
3
|
+
<p align="center">
|
|
4
|
+
<a href="https://pypi.org/project/github-bot-api"><img alt="PyPI - Python Version" src="https://img.shields.io/pypi/pyversions/github-bot-api"></a></p>
|
|
5
|
+
|
|
6
|
+
[PyGithub]: https://pypi.org/project/PyGithub/
|
|
7
|
+
|
|
8
|
+
A thin Python library for creating GitHub bots and webhooks in Python with [PyGithub].
|
|
9
|
+
|
|
10
|
+
```python
|
|
11
|
+
from github import Github
|
|
12
|
+
from github_bot_api import GithubApp
|
|
13
|
+
from pathlib import Path
|
|
14
|
+
|
|
15
|
+
app = GithubApp(
|
|
16
|
+
user_agent='my-bot/0.0.0',
|
|
17
|
+
app_id="67890",
|
|
18
|
+
private_key=Path("app-private.key").read_text(),
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
client: Github = app.installation_client(12345)
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
For more examples, check out the [documentation](https://niklasrosenstein.github.io/python-github-bot-api/).
|
|
@@ -4,11 +4,11 @@ build-backend = "poetry.core.masonry.api"
|
|
|
4
4
|
|
|
5
5
|
[tool.poetry]
|
|
6
6
|
name = "github-bot-api"
|
|
7
|
-
version = "0.
|
|
7
|
+
version = "0.6.0"
|
|
8
8
|
description = "API for creating GitHub bots and webhooks in Python."
|
|
9
9
|
authors = ["Niklas Rosenstein <rosensteinniklas@gmail.com>"]
|
|
10
10
|
license = "MIT"
|
|
11
|
-
readme = "
|
|
11
|
+
readme = "README.md"
|
|
12
12
|
packages = [{ include = "github_bot_api", from = "src" }]
|
|
13
13
|
classifiers = [
|
|
14
14
|
"Intended Audience :: Developers",
|
|
@@ -24,14 +24,11 @@ keywords = []
|
|
|
24
24
|
[tool.poetry.urls]
|
|
25
25
|
"Bug Tracker" = "https://github.com/NiklasRosenstein/python-github-bot-api/issues"
|
|
26
26
|
Documentation = "https://niklasrosenstein.github.io/python-github-bot-api/"
|
|
27
|
-
Homepage = "https://github.com/NiklasRosenstein/python-github-bot-api"
|
|
28
27
|
Repository = "https://github.com/NiklasRosenstein/python-github-bot-api"
|
|
29
28
|
|
|
30
29
|
[tool.poetry.dependencies]
|
|
31
30
|
python = "^3.8"
|
|
32
|
-
|
|
33
|
-
cryptography = "^39.0.2"
|
|
34
|
-
Deprecated = "^1.2.13"
|
|
31
|
+
cryptography = "^42.0.5"
|
|
35
32
|
flask = { version = "*", optional = true }
|
|
36
33
|
PyGithub = { version = "^1.58", optional = true }
|
|
37
34
|
PyJWT = "^2.6.0"
|
|
@@ -44,7 +41,6 @@ flake8 = "*"
|
|
|
44
41
|
isort = "*"
|
|
45
42
|
mypy = "*"
|
|
46
43
|
pytest = "*"
|
|
47
|
-
types-deprecated = "*"
|
|
48
44
|
types-flask = "*"
|
|
49
45
|
types-requests = "*"
|
|
50
46
|
|
|
@@ -8,13 +8,12 @@ import sys
|
|
|
8
8
|
import threading
|
|
9
9
|
import typing as t
|
|
10
10
|
|
|
11
|
-
import deprecated
|
|
12
11
|
import requests
|
|
13
12
|
import urllib3
|
|
14
|
-
from nr.functional import coalesce
|
|
15
13
|
|
|
16
14
|
from . import __version__
|
|
17
15
|
from .token import InstallationTokenSupplier, JwtSupplier, TokenInfo
|
|
16
|
+
from .utils.functions import coalesce
|
|
18
17
|
|
|
19
18
|
T = t.TypeVar("T")
|
|
20
19
|
logger = logging.getLogger(__name__)
|
|
@@ -66,38 +65,21 @@ class GithubClientSettings:
|
|
|
66
65
|
class GithubApp:
|
|
67
66
|
"""
|
|
68
67
|
Represents a GitHub application and all the required details.
|
|
69
|
-
|
|
70
|
-
# Example
|
|
71
|
-
|
|
72
|
-
```py
|
|
73
|
-
import os
|
|
74
|
-
from github_bot_api import GithubApp
|
|
75
|
-
|
|
76
|
-
with open(os.environ['PRIVATE_KEY_FILE']) as fp:
|
|
77
|
-
private_key = fp.read()
|
|
78
|
-
|
|
79
|
-
app = GithubApp(
|
|
80
|
-
user_agent='my-bot/0.0.0',
|
|
81
|
-
app_id=int(os.environ['APP_ID']),
|
|
82
|
-
private_key=private_key)
|
|
83
|
-
|
|
84
|
-
print(app.app_client().get_app().owner)
|
|
85
|
-
```
|
|
86
68
|
"""
|
|
87
69
|
|
|
88
70
|
PUBLIC_GITHUB_V3_API_URL = "https://api.github.com"
|
|
89
71
|
|
|
90
|
-
#: User agent of the application. This will be respected in #get_user_agent().
|
|
91
72
|
user_agent: str
|
|
73
|
+
"""User agent of the application. This will be respected in #get_user_agent()."""
|
|
92
74
|
|
|
93
|
-
#: GitHub Application ID.
|
|
94
75
|
app_id: int
|
|
76
|
+
"""GitHub Application ID."""
|
|
95
77
|
|
|
96
|
-
#: RSA private key to sign the JWT with.
|
|
97
78
|
private_key: str
|
|
79
|
+
"""RSA private key to sign the JWT with."""
|
|
98
80
|
|
|
99
|
-
#: GitHub API base URL. Defaults to the public GitHub API.
|
|
100
81
|
v3_api_url: str = PUBLIC_GITHUB_V3_API_URL
|
|
82
|
+
"""GitHub API base URL. Defaults to the public GitHub API."""
|
|
101
83
|
|
|
102
84
|
def __post_init__(self):
|
|
103
85
|
self._jwt_supplier = JwtSupplier(self.app_id, self.private_key)
|
|
@@ -133,15 +115,6 @@ class GithubApp:
|
|
|
133
115
|
|
|
134
116
|
return JwtSupplier(self.app_id, self.private_key)
|
|
135
117
|
|
|
136
|
-
@property
|
|
137
|
-
@deprecated.deprecated(reason="use GithubApp.app_client() instead", version="0.4.0")
|
|
138
|
-
def client(self) -> "github.Github":
|
|
139
|
-
"""
|
|
140
|
-
Use #app_client() instead.
|
|
141
|
-
"""
|
|
142
|
-
|
|
143
|
-
return self.app_client()
|
|
144
|
-
|
|
145
118
|
def app_client(self, settings: t.Union[GithubClientSettings, t.Dict[str, t.Any], None] = None) -> "github.Github":
|
|
146
119
|
"""
|
|
147
120
|
Returns a PyGithub client for your GitHub application.
|
|
@@ -21,22 +21,22 @@ class Event:
|
|
|
21
21
|
Represents a GitHub webhook event.
|
|
22
22
|
"""
|
|
23
23
|
|
|
24
|
-
#: The name of the event. Could be `pull_request`, for example.
|
|
25
24
|
name: str
|
|
25
|
+
""" The name of the event. Could be `pull_request`, for example."""
|
|
26
26
|
|
|
27
|
-
#: The delivery ID of the event.
|
|
28
27
|
delivery_id: str
|
|
28
|
+
"""The delivery ID of the event."""
|
|
29
29
|
|
|
30
|
-
#: The signature of the event. Will only be set if a Webhook-secret is configured on the
|
|
31
|
-
#: client side (e.g. in #Webhook.secret / if the *webhook_secret* parameter is passed to
|
|
32
|
-
#: #accept_event()).
|
|
33
30
|
signature: t.Optional[str]
|
|
31
|
+
"""The signature of the event. Will only be set if a Webhook-secret is configured on the
|
|
32
|
+
client side (e.g. in [`Webhook.secret`][github_bot_api.webhook.Webhook] / if the *webhook_secret* parameter is
|
|
33
|
+
passed to [`accept_event()`][github_bot_api.event.accept_event])."""
|
|
34
34
|
|
|
35
|
-
#: The user agent invoking the webhook.
|
|
36
35
|
user_agent: str
|
|
36
|
+
"""The user agent invoking the webhook."""
|
|
37
37
|
|
|
38
|
-
#: The event payload.
|
|
39
38
|
payload: t.Dict[str, t.Any]
|
|
39
|
+
"""The event payload."""
|
|
40
40
|
|
|
41
41
|
|
|
42
42
|
def accept_event(
|
|
@@ -47,12 +47,12 @@ def accept_event(
|
|
|
47
47
|
"""
|
|
48
48
|
Converts thee HTTP *headers* and the *raw_body* to an #Event object.
|
|
49
49
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
50
|
+
Args:
|
|
51
|
+
headers: The HTTP headers. Must have `X-Github-Event`, `X-Github-Delivery`, `User-Agent`, `Content-Type`.
|
|
52
|
+
May have `X-Hub-Signature` or `X-Hub-Signature-256`.
|
|
53
|
+
raw_body: The raw request body for the event. This is converted into a JSON payload.
|
|
54
|
+
webhook_secret: If specified, the `X-Hub-Signature` or `X-Hub-Signature-256` headers are used to verify
|
|
55
|
+
the signature of the payload. If not specified, the client does not validate the signature.
|
|
56
56
|
"""
|
|
57
57
|
|
|
58
58
|
event_name = headers.get("X-GitHub-Event")
|
|
@@ -64,7 +64,7 @@ def accept_event(
|
|
|
64
64
|
|
|
65
65
|
if not event_name or not delivery_id or not user_agent or not content_type:
|
|
66
66
|
raise InvalidRequest("missing required headers")
|
|
67
|
-
if webhook_secret is not None and not
|
|
67
|
+
if webhook_secret is not None and not signature_1 and not signature_256:
|
|
68
68
|
raise InvalidRequest("webhook secret is configured but no signature header was received")
|
|
69
69
|
|
|
70
70
|
mime_type, parameters = get_mime_components(content_type)
|
|
@@ -15,9 +15,9 @@ def compute_signature(payload: bytes, secret: bytes, algo: str = "sha256") -> st
|
|
|
15
15
|
algo: The hash algorithm to use, must be `sha1` or `sha256`.
|
|
16
16
|
"""
|
|
17
17
|
|
|
18
|
-
if algo
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
if algo in {"sha1", "sha256"}:
|
|
19
|
+
return f"{algo}={hmac.new(secret, payload, algo).hexdigest()}"
|
|
20
|
+
raise ValueError(f"algo must be {{sha1, sha256}}, got {algo!r}")
|
|
21
21
|
|
|
22
22
|
|
|
23
23
|
def check_signature(sig: str, payload: bytes, secret: bytes, algo: str = "sha256") -> None:
|
|
@@ -59,7 +59,7 @@ def create_jwt(app_id: int, expires_in: int, private_key: str) -> TokenInfo:
|
|
|
59
59
|
|
|
60
60
|
now = int(time.time())
|
|
61
61
|
exp = now + expires_in
|
|
62
|
-
payload = {"iss":
|
|
62
|
+
payload = {"iss": app_id, "iat": now, "exp": exp}
|
|
63
63
|
token = jwt.encode(payload, private_key, algorithm="RS256")
|
|
64
64
|
return TokenInfo(exp, "Bearer", token)
|
|
65
65
|
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
from typing import Optional, TypeVar, overload
|
|
2
|
+
|
|
3
|
+
T = TypeVar("T")
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
@overload
|
|
7
|
+
def coalesce(value: Optional[T], fallback: T) -> T: ...
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
@overload
|
|
11
|
+
def coalesce(value: Optional[T], *values: Optional[T]) -> Optional[T]: ...
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
@overload
|
|
15
|
+
def coalesce(value: Optional[T], *values: Optional[T], fallback: T) -> T: ...
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def coalesce(value: Optional[T], *values: Optional[T], fallback: Optional[T] = None) -> Optional[T]:
|
|
19
|
+
"""
|
|
20
|
+
Returns the first value that is not `None`. If a not-None fallback is specified, the function is guaranteed
|
|
21
|
+
to return a not-Non value.
|
|
22
|
+
"""
|
|
23
|
+
|
|
24
|
+
if value is not None:
|
|
25
|
+
return value
|
|
26
|
+
value = next((x for x in values if x is not None), None)
|
|
27
|
+
if value is not None:
|
|
28
|
+
return value
|
|
29
|
+
return fallback
|
|
@@ -67,9 +67,6 @@ class Webhook:
|
|
|
67
67
|
matched = True
|
|
68
68
|
if handler.func(event):
|
|
69
69
|
return True
|
|
70
|
-
else
|
|
71
|
-
logger.info(
|
|
72
|
-
f'Event %r (id: %r) goes {"unhandled" if matched else "unmatched"}.', event.name, event.delivery_id
|
|
73
|
-
)
|
|
70
|
+
logger.info(f'Event %r (id: %r) goes {"unhandled" if matched else "unmatched"}.', event.name, event.delivery_id)
|
|
74
71
|
|
|
75
72
|
return matched
|
github_bot_api-0.5.2/LICENSE.txt
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
The MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2021 Niklas Rosenstein
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
this software and associated documentation files (the "Software"), to deal in
|
|
7
|
-
Software without restriction, including without limitation the rights to use,
|
|
8
|
-
modify, merge, publish, distribute, sublicense, and/or sell copies of the
|
|
9
|
-
and to permit persons to whom the Software is furnished to do so, subject to
|
|
10
|
-
following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
|
17
|
-
PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
18
|
-
BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
|
|
19
|
-
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
|
|
20
|
-
USE OR OTHER DEALINGS IN THE SOFTWARE.
|
github_bot_api-0.5.2/PKG-INFO
DELETED
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.1
|
|
2
|
-
Name: github-bot-api
|
|
3
|
-
Version: 0.5.2
|
|
4
|
-
Summary: API for creating GitHub bots and webhooks in Python.
|
|
5
|
-
License: MIT
|
|
6
|
-
Author: Niklas Rosenstein
|
|
7
|
-
Author-email: rosensteinniklas@gmail.com
|
|
8
|
-
Requires-Python: >=3.8,<4.0
|
|
9
|
-
Classifier: Intended Audience :: Developers
|
|
10
|
-
Classifier: License :: OSI Approved :: MIT License
|
|
11
|
-
Classifier: Programming Language :: Python :: 3
|
|
12
|
-
Classifier: Programming Language :: Python :: 3.8
|
|
13
|
-
Classifier: Programming Language :: Python :: 3.9
|
|
14
|
-
Classifier: Programming Language :: Python :: 3.10
|
|
15
|
-
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
-
Classifier: Programming Language :: Python :: 3
|
|
17
|
-
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
-
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
-
Classifier: Programming Language :: Python :: 3.8
|
|
20
|
-
Classifier: Programming Language :: Python :: 3.9
|
|
21
|
-
Requires-Dist: Deprecated (>=1.2.13,<2.0.0)
|
|
22
|
-
Requires-Dist: PyGithub (>=1.58,<2.0)
|
|
23
|
-
Requires-Dist: PyJWT (>=2.6.0,<3.0.0)
|
|
24
|
-
Requires-Dist: cryptography (>=39.0.2,<40.0.0)
|
|
25
|
-
Requires-Dist: flask
|
|
26
|
-
Requires-Dist: nr.functional (>=0.2.0,<0.3.0)
|
|
27
|
-
Requires-Dist: requests (>=2.28.2,<3.0.0)
|
|
28
|
-
Requires-Dist: urllib3 (>=1.26.15,<2.0.0)
|
|
29
|
-
Project-URL: Bug Tracker, https://github.com/NiklasRosenstein/python-github-bot-api/issues
|
|
30
|
-
Project-URL: Documentation, https://niklasrosenstein.github.io/python-github-bot-api/
|
|
31
|
-
Project-URL: Homepage, https://github.com/NiklasRosenstein/python-github-bot-api
|
|
32
|
-
Project-URL: Repository, https://github.com/NiklasRosenstein/python-github-bot-api
|
|
33
|
-
Description-Content-Type: text/markdown
|
|
34
|
-
|
|
35
|
-
# github-bot-api
|
|
36
|
-
|
|
37
|
-
API for creating GitHub bots and webhooks in Python.
|
|
38
|
-
|
|
39
|
-
> Note: If you want to make use of `GithubApp.app_client()` or `GithubApp.installation_client()`, you
|
|
40
|
-
> need to install `PyGithub>=1.58`.
|
|
41
|
-
|
|
42
|
-
## Quickstart (Webhook)
|
|
43
|
-
|
|
44
|
-
1. Create a new Smee channel on https://smee.io
|
|
45
|
-
2. Install `smee-client` (e.g. `yarn global add smee-client`)
|
|
46
|
-
3. Run `smee -u <SMEE_CHANNEL_URL> -P /event-handler -p 5000`
|
|
47
|
-
4. Create a Python script with the below contents and run it
|
|
48
|
-
|
|
49
|
-
```python
|
|
50
|
-
from github_bot_api import Event, Webhook
|
|
51
|
-
from github_bot_api.flask import create_flask_app
|
|
52
|
-
|
|
53
|
-
def on_any_event(event: Event) -> bool:
|
|
54
|
-
print(event)
|
|
55
|
-
return True
|
|
56
|
-
|
|
57
|
-
webhook = Webhook(secret=None)
|
|
58
|
-
webhook.listen('*', on_any_event)
|
|
59
|
-
|
|
60
|
-
import os; os.environ['FLASK_ENV'] = 'development'
|
|
61
|
-
flask_app = create_flask_app(__name__, webhook)
|
|
62
|
-
flask_app.run()
|
|
63
|
-
```
|
|
64
|
-
|
|
65
|
-
## Quickstart (Application)
|
|
66
|
-
|
|
67
|
-
1. Create a GitHub App, including a private key
|
|
68
|
-
2. Set the `APP_ID` and `PRIVATE_KEY_FILE` environment variables
|
|
69
|
-
3. Run the following Python script
|
|
70
|
-
|
|
71
|
-
```python
|
|
72
|
-
import os
|
|
73
|
-
from github_bot_api import GithubApp
|
|
74
|
-
|
|
75
|
-
with open(os.environ['PRIVATE_KEY_FILE']) as fp:
|
|
76
|
-
private_key = fp.read()
|
|
77
|
-
|
|
78
|
-
app = GithubApp(
|
|
79
|
-
user_agent='my-bot/0.0.0',
|
|
80
|
-
app_id=int(os.environ['APP_ID']),
|
|
81
|
-
private_key=private_key)
|
|
82
|
-
|
|
83
|
-
print(app.app_client().get_app().owner)
|
|
84
|
-
```
|
|
85
|
-
|
|
86
|
-
## Combined Example
|
|
87
|
-
|
|
88
|
-
```python
|
|
89
|
-
# ...
|
|
90
|
-
|
|
91
|
-
app = GithubApp(...)
|
|
92
|
-
webhook = Webhook()
|
|
93
|
-
|
|
94
|
-
@webhook.listen('pull_request')
|
|
95
|
-
def on_pull_request(event: Event) -> bool:
|
|
96
|
-
client = app.installation_client(event.payload['installation']['id'])
|
|
97
|
-
repo = client.get_repo(event['repository']['full_name'])
|
|
98
|
-
pr = repo.get_pull(event['pull_request']['number'])
|
|
99
|
-
pr.create_issue_comment('Hello from my own bot!')
|
|
100
|
-
return True
|
|
101
|
-
|
|
102
|
-
# ...
|
|
103
|
-
```
|
|
104
|
-
|
github_bot_api-0.5.2/readme.md
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
# github-bot-api
|
|
2
|
-
|
|
3
|
-
API for creating GitHub bots and webhooks in Python.
|
|
4
|
-
|
|
5
|
-
> Note: If you want to make use of `GithubApp.app_client()` or `GithubApp.installation_client()`, you
|
|
6
|
-
> need to install `PyGithub>=1.58`.
|
|
7
|
-
|
|
8
|
-
## Quickstart (Webhook)
|
|
9
|
-
|
|
10
|
-
1. Create a new Smee channel on https://smee.io
|
|
11
|
-
2. Install `smee-client` (e.g. `yarn global add smee-client`)
|
|
12
|
-
3. Run `smee -u <SMEE_CHANNEL_URL> -P /event-handler -p 5000`
|
|
13
|
-
4. Create a Python script with the below contents and run it
|
|
14
|
-
|
|
15
|
-
```python
|
|
16
|
-
from github_bot_api import Event, Webhook
|
|
17
|
-
from github_bot_api.flask import create_flask_app
|
|
18
|
-
|
|
19
|
-
def on_any_event(event: Event) -> bool:
|
|
20
|
-
print(event)
|
|
21
|
-
return True
|
|
22
|
-
|
|
23
|
-
webhook = Webhook(secret=None)
|
|
24
|
-
webhook.listen('*', on_any_event)
|
|
25
|
-
|
|
26
|
-
import os; os.environ['FLASK_ENV'] = 'development'
|
|
27
|
-
flask_app = create_flask_app(__name__, webhook)
|
|
28
|
-
flask_app.run()
|
|
29
|
-
```
|
|
30
|
-
|
|
31
|
-
## Quickstart (Application)
|
|
32
|
-
|
|
33
|
-
1. Create a GitHub App, including a private key
|
|
34
|
-
2. Set the `APP_ID` and `PRIVATE_KEY_FILE` environment variables
|
|
35
|
-
3. Run the following Python script
|
|
36
|
-
|
|
37
|
-
```python
|
|
38
|
-
import os
|
|
39
|
-
from github_bot_api import GithubApp
|
|
40
|
-
|
|
41
|
-
with open(os.environ['PRIVATE_KEY_FILE']) as fp:
|
|
42
|
-
private_key = fp.read()
|
|
43
|
-
|
|
44
|
-
app = GithubApp(
|
|
45
|
-
user_agent='my-bot/0.0.0',
|
|
46
|
-
app_id=int(os.environ['APP_ID']),
|
|
47
|
-
private_key=private_key)
|
|
48
|
-
|
|
49
|
-
print(app.app_client().get_app().owner)
|
|
50
|
-
```
|
|
51
|
-
|
|
52
|
-
## Combined Example
|
|
53
|
-
|
|
54
|
-
```python
|
|
55
|
-
# ...
|
|
56
|
-
|
|
57
|
-
app = GithubApp(...)
|
|
58
|
-
webhook = Webhook()
|
|
59
|
-
|
|
60
|
-
@webhook.listen('pull_request')
|
|
61
|
-
def on_pull_request(event: Event) -> bool:
|
|
62
|
-
client = app.installation_client(event.payload['installation']['id'])
|
|
63
|
-
repo = client.get_repo(event['repository']['full_name'])
|
|
64
|
-
pr = repo.get_pull(event['pull_request']['number'])
|
|
65
|
-
pr.create_issue_comment('Hello from my own bot!')
|
|
66
|
-
return True
|
|
67
|
-
|
|
68
|
-
# ...
|
|
69
|
-
```
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|