Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added efficiency improvement to get_installation #191

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 8 additions & 12 deletions blurb_it/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import jwt
from aiohttp_session import get_session
from gidgethub import BadRequest

from blurb_it import error

Expand Down Expand Up @@ -66,18 +67,13 @@ def get_jwt(app_id, private_key):


async def get_installation(gh, jwt, username):

async for installation in gh.getiter(
"/app/installations",
jwt=jwt,
accept="application/vnd.github.machine-man-preview+json",
):
if installation["account"]["login"] == username:
return installation

raise error.InstallationNotFound(
f"Can't find installation by that user: {username}"
)
try:
return await gh.getitem(f"/users/{username}/installation", jwt=jwt)
except BadRequest:
# will raise a 401 if no installation for this user
raise error.InstallationNotFound(
f"Can't find installation by that user: {username}"
)


async def get_installation_access_token(gh, jwt, installation_id):
Expand Down