mirror of
https://github.com/status-im/PyGithub.git
synced 2026-08-31 19:01:15 +00:00
Sync GithubIntegration __init__ arguments with github.Github (#2556)
Github and GithubIntegration now both support the same (full) set of Requester arguments. Creating a Github instance for a Github App Installation coming from GithubIntegration uses the same Requester arguments (except for auth).
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
import warnings
|
||||
|
||||
import deprecated
|
||||
import urllib3
|
||||
|
||||
import github
|
||||
from github import Consts
|
||||
from github.Auth import AppAuth
|
||||
from github.GithubApp import GithubApp
|
||||
@@ -17,6 +19,7 @@ class GithubIntegration:
|
||||
Main class to obtain tokens for a GitHub integration.
|
||||
"""
|
||||
|
||||
# keep non-deprecated arguments in-sync with Requester
|
||||
# v2: remove integration_id, private_key, jwt_expiry, jwt_issued_at and jwt_algorithm
|
||||
# v2: move auth to the front of arguments
|
||||
# v2: add * before first argument so all arguments must be named,
|
||||
@@ -26,6 +29,12 @@ class GithubIntegration:
|
||||
integration_id=None,
|
||||
private_key=None,
|
||||
base_url=Consts.DEFAULT_BASE_URL,
|
||||
timeout=Consts.DEFAULT_TIMEOUT,
|
||||
user_agent=Consts.DEFAULT_USER_AGENT,
|
||||
per_page=Consts.DEFAULT_PER_PAGE,
|
||||
verify=True,
|
||||
retry=None,
|
||||
pool_size=None,
|
||||
jwt_expiry=Consts.DEFAULT_JWT_EXPIRY,
|
||||
jwt_issued_at=Consts.DEFAULT_JWT_ISSUED_AT,
|
||||
jwt_algorithm=Consts.DEFAULT_JWT_ALGORITHM,
|
||||
@@ -35,8 +44,15 @@ class GithubIntegration:
|
||||
:param integration_id: int deprecated, use auth=github.Auth.AppAuth(...) instead
|
||||
:param private_key: string deprecated, use auth=github.Auth.AppAuth(...) instead
|
||||
:param base_url: string
|
||||
:param timeout: integer
|
||||
:param user_agent: string
|
||||
:param per_page: int
|
||||
:param verify: boolean or string
|
||||
:param retry: int or urllib3.util.retry.Retry object
|
||||
:param pool_size: int
|
||||
:param jwt_expiry: int deprecated, use auth=github.Auth.AppAuth(...) instead
|
||||
:param jwt_issued_at: int deprecated, use auth=github.Auth.AppAuth(...) instead
|
||||
:param jwt_algorithm: string deprecated, use auth=github.Auth.AppAuth(...) instead
|
||||
:param auth: authentication method
|
||||
"""
|
||||
if integration_id is not None:
|
||||
@@ -46,6 +62,16 @@ class GithubIntegration:
|
||||
private_key, str
|
||||
), "supplied private key should be a string"
|
||||
assert isinstance(base_url, str), base_url
|
||||
assert isinstance(timeout, int), timeout
|
||||
assert user_agent is None or isinstance(user_agent, str), user_agent
|
||||
assert isinstance(per_page, int), per_page
|
||||
assert isinstance(verify, (bool, str)), verify
|
||||
assert (
|
||||
retry is None
|
||||
or isinstance(retry, int)
|
||||
or isinstance(retry, urllib3.util.Retry)
|
||||
), retry
|
||||
assert pool_size is None or isinstance(pool_size, int), pool_size
|
||||
assert isinstance(jwt_expiry, int), jwt_expiry
|
||||
assert Consts.MIN_JWT_EXPIRY <= jwt_expiry <= Consts.MAX_JWT_EXPIRY, jwt_expiry
|
||||
assert isinstance(jwt_issued_at, int)
|
||||
@@ -81,14 +107,21 @@ class GithubIntegration:
|
||||
self.__requester = Requester(
|
||||
auth=auth,
|
||||
base_url=self.base_url,
|
||||
timeout=Consts.DEFAULT_TIMEOUT,
|
||||
user_agent="PyGithub/Python",
|
||||
per_page=Consts.DEFAULT_PER_PAGE,
|
||||
verify=True,
|
||||
retry=None,
|
||||
pool_size=None,
|
||||
timeout=timeout,
|
||||
user_agent=user_agent,
|
||||
per_page=per_page,
|
||||
verify=verify,
|
||||
retry=retry,
|
||||
pool_size=pool_size,
|
||||
)
|
||||
|
||||
def get_github_for_installation(self, installation_id):
|
||||
# The installation has to authenticate as an installation, not an app
|
||||
auth = self.auth.get_installation_auth(
|
||||
installation_id, requester=self.__requester
|
||||
)
|
||||
return github.Github(**self.__requester.withAuth(auth).kwargs)
|
||||
|
||||
def _get_headers(self):
|
||||
"""
|
||||
Get headers for the requests.
|
||||
|
||||
Reference in New Issue
Block a user