def get_installations(integration): # FIXME(sileht): Need to be in github libs response = requests.get( "https://api.github.com/app/installations", headers={ "Authorization": "Bearer {}".format(integration.create_jwt()), "Accept": "application/vnd.github.machine-man-preview+json", "User-Agent": "PyGithub/Python" }, ) if response.status_code == 200: return response.json() elif response.status_code == 403: raise GithubException.BadCredentialsException( status=response.status_code, data=response.text ) elif response.status_code == 404: raise GithubException.UnknownObjectException( status=response.status_code, data=response.text ) raise GithubException.GithubException( status=response.status_code, data=response.text )
def get_installations(integration): # FIXME(sileht): Need to be in github libs conn = HTTPSConnection("api.github.com") conn.request( method="GET", url="/app/installations", headers={ "Authorization": "Bearer {}".format(integration.create_jwt()), "Accept": "application/vnd.github.machine-man-preview+json", "User-Agent": "PyGithub/Python" }, ) response = conn.getresponse() response_text = response.read() if six.PY3: response_text = response_text.decode('utf-8') conn.close() if response.status == 200: return ujson.loads(response_text) elif response.status == 403: raise GithubException.BadCredentialsException(status=response.status, data=response_text) elif response.status == 404: raise GithubException.UnknownObjectException(status=response.status, data=response_text) raise GithubException.GithubException(status=response.status, data=response_text)
def _get_installation_access_token(self, installation_id): """ Get an access token for the given installation id. POSTs https://api.github.com/installations/<installation_id>/access_tokens :param user_id: int :param installation_id: int :return: :class:`github.InstallationAuthorization.InstallationAuthorization` """ conn = HTTPSConnection("api.github.com") conn.request( method="POST", url="/installations/{}/access_tokens".format(installation_id), headers={ "Authorization": "Bearer {}".format(self._create_jwt().decode()), "Accept": "application/vnd.github.machine-man-preview+json", "User-Agent": "LaraTUB/lara" } ) response = conn.getresponse() response_text = response.read() response_text = response_text.decode('utf-8') conn.close() if response.status == 201: data = json.loads(response_text) return InstallationAuthorization.InstallationAuthorization( requester=None, # not required, this is a NonCompletableGithubObject headers={}, # not required, this is a NonCompletableGithubObject attributes=data, completed=True ).token elif response.status == 403: raise GithubException.BadCredentialsException( status=response.status, data=response_text ) elif response.status == 404: raise GithubException.UnknownObjectException( status=response.status, data=response_text ) raise GithubException.GithubException( status=response.status, data=response_text )