diff --git a/.config.yml b/.config.yml index 4002c61..550ebbd 100644 --- a/.config.yml +++ b/.config.yml @@ -4,3 +4,6 @@ orgs: pem: app_id: installation_id: + # If using GitHub Enterprise, set base_url. + # GitHub Enterprise is supported by these examples: python-pygithub + # base_url: https://ghe.example.com/api/v3 diff --git a/python-pygithub/.gitignore b/python-pygithub/.gitignore new file mode 100644 index 0000000..214063e --- /dev/null +++ b/python-pygithub/.gitignore @@ -0,0 +1,2 @@ +# Pytyon 3 bytecode +__pycache__/ diff --git a/python-pygithub/lib/__init__.py b/python-pygithub/lib/__init__.py index 00a6705..8ec3d2a 100644 --- a/python-pygithub/lib/__init__.py +++ b/python-pygithub/lib/__init__.py @@ -15,18 +15,29 @@ def wrapper(self, *args, **kwargs): self.github_client() if not self.gh or self.is_expired() else None return func(self, *args, **kwargs) return wrapper - + def is_expired(self): return datetime.now().timestamp() + 60 >= self.expires_at.timestamp() def token(self): - return GithubIntegration( - self.meta.get("app_id"), self.private_key - ).get_access_token(self.meta.get("installation_id")) + kwargs = { + "integration_id": self.meta.get("app_id"), + "private_key": self.private_key, + } + if self.meta.get("base_url"): + kwargs["base_url"] = self.meta.get("base_url") + integration = GithubIntegration( + **kwargs, + ) + token = integration.get_access_token(self.meta.get("installation_id")) + return token def github_client(self): self._auth = self.token() - self.gh = Github(self._auth.token) + kwargs = {"login_or_token": self._auth.token} + if self.meta.get("base_url"): + kwargs["base_url"] = self.meta.get("base_url") + self.gh = Github(**kwargs) self.expires_at = self._auth.expires_at.replace(tzinfo=timezone.utc)