github-bot-api 0.5.2__tar.gz → 0.7.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.
Files changed (23) hide show
  1. github_bot_api-0.7.0/PKG-INFO +49 -0
  2. github_bot_api-0.7.0/README.md +24 -0
  3. github_bot_api-0.7.0/pyproject.toml +69 -0
  4. github_bot_api-0.7.0/src/github_bot_api/__init__.py +8 -0
  5. {github_bot_api-0.5.2 → github_bot_api-0.7.0}/src/github_bot_api/app.py +5 -32
  6. {github_bot_api-0.5.2 → github_bot_api-0.7.0}/src/github_bot_api/event.py +14 -14
  7. {github_bot_api-0.5.2 → github_bot_api-0.7.0}/src/github_bot_api/signature.py +3 -3
  8. {github_bot_api-0.5.2 → github_bot_api-0.7.0}/src/github_bot_api/token.py +1 -1
  9. github_bot_api-0.7.0/src/github_bot_api/utils/functions.py +29 -0
  10. {github_bot_api-0.5.2 → github_bot_api-0.7.0}/src/github_bot_api/webhook.py +1 -4
  11. github_bot_api-0.5.2/LICENSE.txt +0 -20
  12. github_bot_api-0.5.2/PKG-INFO +0 -104
  13. github_bot_api-0.5.2/pyproject.toml +0 -86
  14. github_bot_api-0.5.2/readme.md +0 -69
  15. github_bot_api-0.5.2/src/github_bot_api/__init__.py +0 -8
  16. {github_bot_api-0.5.2 → github_bot_api-0.7.0}/LICENSE +0 -0
  17. {github_bot_api-0.5.2 → github_bot_api-0.7.0}/src/github_bot_api/app_test.py +0 -0
  18. {github_bot_api-0.5.2 → github_bot_api-0.7.0}/src/github_bot_api/flask.py +0 -0
  19. {github_bot_api-0.5.2 → github_bot_api-0.7.0}/src/github_bot_api/py.typed +0 -0
  20. /github_bot_api-0.5.2/src/github_bot_api/__init__test.py → /github_bot_api-0.7.0/src/github_bot_api/tests/test_import.py +0 -0
  21. {github_bot_api-0.5.2 → github_bot_api-0.7.0}/src/github_bot_api/utils/__init__.py +0 -0
  22. {github_bot_api-0.5.2 → github_bot_api-0.7.0}/src/github_bot_api/utils/mime.py +0 -0
  23. {github_bot_api-0.5.2 → github_bot_api-0.7.0}/src/github_bot_api/utils/types.py +0 -0
@@ -0,0 +1,49 @@
1
+ Metadata-Version: 2.1
2
+ Name: github-bot-api
3
+ Version: 0.7.0
4
+ Summary: API for creating GitHub bots and webhooks in Python.
5
+ Author-Email: Niklas Rosenstein <rosensteinniklas@gmail.com>
6
+ License: MIT
7
+ Classifier: Intended Audience :: Developers
8
+ Classifier: License :: OSI Approved :: MIT License
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: Programming Language :: Python :: 3.9
11
+ Classifier: Programming Language :: Python :: 3.10
12
+ Classifier: Programming Language :: Python :: 3.11
13
+ Classifier: Programming Language :: Python :: 3.12
14
+ Classifier: Programming Language :: Python :: 3.13
15
+ Project-URL: Bug Tracker, https://github.com/NiklasRosenstein/python-github-bot-api/issues
16
+ Project-URL: Documentation, https://niklasrosenstein.github.io/python-github-bot-api/
17
+ Project-URL: Repository, https://github.com/NiklasRosenstein/python-github-bot-api
18
+ Requires-Python: <4.0,>=3.9
19
+ Requires-Dist: cryptography<44.0.1,>=44.0.0
20
+ Requires-Dist: pygithub>=2.5.0
21
+ Requires-Dist: PyJWT<3.0.0,>=2.6.0
22
+ Requires-Dist: requests<3.0.0,>=2.28.2
23
+ Requires-Dist: urllib3<2.4.0,>=2.3.0
24
+ Description-Content-Type: text/markdown
25
+
26
+ <p align="center"><img src="https://i.imgur.com/5SiDsz8.png"></p>
27
+ <h1 align="center">python-github-bot-api</h1>
28
+ <p align="center">
29
+ <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>
30
+
31
+ [PyGithub]: https://pypi.org/project/PyGithub/
32
+
33
+ A thin Python library for creating GitHub bots and webhooks in Python with [PyGithub].
34
+
35
+ ```python
36
+ from github import Github
37
+ from github_bot_api import GithubApp
38
+ from pathlib import Path
39
+
40
+ app = GithubApp(
41
+ user_agent='my-bot/0.0.0',
42
+ app_id="67890",
43
+ private_key=Path("app-private.key").read_text(),
44
+ )
45
+
46
+ client: Github = app.installation_client(12345)
47
+ ```
48
+
49
+ For more examples, check out the [documentation](https://niklasrosenstein.github.io/python-github-bot-api/).
@@ -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/).
@@ -0,0 +1,69 @@
1
+ [build-system]
2
+ requires = [
3
+ "pdm-backend",
4
+ ]
5
+ build-backend = "pdm.backend"
6
+
7
+ [project]
8
+ authors = [
9
+ { name = "Niklas Rosenstein", email = "rosensteinniklas@gmail.com" },
10
+ ]
11
+ requires-python = "<4.0,>=3.9"
12
+ dependencies = [
13
+ "cryptography<44.0.1,>=44.0.0",
14
+ "pygithub>=2.5.0",
15
+ "PyJWT<3.0.0,>=2.6.0",
16
+ "requests<3.0.0,>=2.28.2",
17
+ "urllib3<2.4.0,>=2.3.0",
18
+ ]
19
+ name = "github-bot-api"
20
+ version = "0.7.0"
21
+ description = "API for creating GitHub bots and webhooks in Python."
22
+ readme = "README.md"
23
+ classifiers = [
24
+ "Intended Audience :: Developers",
25
+ "License :: OSI Approved :: MIT License",
26
+ "Programming Language :: Python :: 3",
27
+ "Programming Language :: Python :: 3.9",
28
+ "Programming Language :: Python :: 3.10",
29
+ "Programming Language :: Python :: 3.11",
30
+ "Programming Language :: Python :: 3.12",
31
+ "Programming Language :: Python :: 3.13",
32
+ ]
33
+ keywords = []
34
+
35
+ [project.license]
36
+ text = "MIT"
37
+
38
+ [project.urls]
39
+ "Bug Tracker" = "https://github.com/NiklasRosenstein/python-github-bot-api/issues"
40
+ Documentation = "https://niklasrosenstein.github.io/python-github-bot-api/"
41
+ Repository = "https://github.com/NiklasRosenstein/python-github-bot-api"
42
+
43
+ [tool.mypy]
44
+ python_version = "3.8"
45
+ explicit_package_bases = true
46
+ mypy_path = [
47
+ "src",
48
+ ]
49
+ namespace_packages = true
50
+ pretty = true
51
+ show_error_codes = true
52
+ show_error_context = true
53
+ warn_no_return = true
54
+ warn_redundant_casts = true
55
+ warn_unreachable = true
56
+ warn_unused_ignores = true
57
+ check_untyped_defs = true
58
+
59
+ [tool.ruff]
60
+ line-length = 120
61
+
62
+ [tool.uv]
63
+ dev-dependencies = [
64
+ "mypy",
65
+ "pytest",
66
+ "ruff>=0.8.5",
67
+ "types-flask",
68
+ "types-requests",
69
+ ]
@@ -0,0 +1,8 @@
1
+ __author__ = "Niklas Rosenstein <nrosenstein@palantir.com>"
2
+ __version__ = "0.7.0"
3
+
4
+ from .app import GithubApp
5
+ from .event import Event, accept_event
6
+ from .webhook import Webhook
7
+
8
+ __all__ = ["GithubApp", "Event", "accept_event", "Webhook"]
@@ -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
- # Arguments
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.
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 (signature_1 or signature_256):
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 not in ("sha1", "sha256"):
19
- raise ValueError(f"algo must be {{sha1, sha256}}, got {algo!r}")
20
- return f"{algo}=" + hmac.new(secret, payload, algo).hexdigest()
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": int(app_id), "iat": now, "exp": exp}
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
@@ -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.
@@ -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
-
@@ -1,86 +0,0 @@
1
- [build-system]
2
- requires = ["poetry-core"]
3
- build-backend = "poetry.core.masonry.api"
4
-
5
- [tool.poetry]
6
- name = "github-bot-api"
7
- version = "0.5.2"
8
- description = "API for creating GitHub bots and webhooks in Python."
9
- authors = ["Niklas Rosenstein <rosensteinniklas@gmail.com>"]
10
- license = "MIT"
11
- readme = "readme.md"
12
- packages = [{ include = "github_bot_api", from = "src" }]
13
- classifiers = [
14
- "Intended Audience :: Developers",
15
- "License :: OSI Approved :: MIT License",
16
- "Programming Language :: Python :: 3",
17
- "Programming Language :: Python :: 3.8",
18
- "Programming Language :: Python :: 3.9",
19
- "Programming Language :: Python :: 3.10",
20
- "Programming Language :: Python :: 3.11"
21
- ]
22
- keywords = []
23
-
24
- [tool.poetry.urls]
25
- "Bug Tracker" = "https://github.com/NiklasRosenstein/python-github-bot-api/issues"
26
- Documentation = "https://niklasrosenstein.github.io/python-github-bot-api/"
27
- Homepage = "https://github.com/NiklasRosenstein/python-github-bot-api"
28
- Repository = "https://github.com/NiklasRosenstein/python-github-bot-api"
29
-
30
- [tool.poetry.dependencies]
31
- python = "^3.8"
32
- "nr.functional" = "^0.2.0"
33
- cryptography = "^39.0.2"
34
- Deprecated = "^1.2.13"
35
- flask = { version = "*", optional = true }
36
- PyGithub = { version = "^1.58", optional = true }
37
- PyJWT = "^2.6.0"
38
- requests = "^2.28.2"
39
- urllib3 = "^1.26.15"
40
-
41
- [tool.poetry.dev-dependencies]
42
- black = "*"
43
- flake8 = "*"
44
- isort = "*"
45
- mypy = "*"
46
- pytest = "*"
47
- types-deprecated = "*"
48
- types-flask = "*"
49
- types-requests = "*"
50
-
51
- [tool.slap]
52
- typed = true
53
-
54
- [tool.slap.test]
55
- check = "slap check"
56
- mypy = "dmypy run src"
57
- pytest = "pytest -vv"
58
- black = "black --check src"
59
- isort = "isort --check-only src"
60
- flake8 = "flake8 src"
61
-
62
- [tool.slap.run]
63
- fmt = "black src && isort src"
64
-
65
- [tool.mypy]
66
- python_version = "3.8"
67
- explicit_package_bases = true
68
- mypy_path = ["src"]
69
- namespace_packages = true
70
- pretty = true
71
- show_error_codes = true
72
- show_error_context = true
73
- # strict = true
74
- warn_no_return = true
75
- warn_redundant_casts = true
76
- warn_unreachable = true
77
- warn_unused_ignores = true
78
- check_untyped_defs = true
79
-
80
- [tool.isort]
81
- profile = "black"
82
- line_length = 120
83
- combine_as_imports = true
84
-
85
- [tool.black]
86
- line-length = 120
@@ -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
- ```
@@ -1,8 +0,0 @@
1
- __author__ = "Niklas Rosenstein <nrosenstein@palantir.com>"
2
- __version__ = "0.5.2"
3
-
4
- from .app import GithubApp
5
- from .event import Event
6
- from .webhook import Webhook
7
-
8
- __all__ = ["GithubApp", "Event", "Webhook"]
File without changes