@@ -37,17 +37,17 @@ async def main(request):
3737
3838 async with aiohttp .ClientSession () as session :
3939 gh = gh_aiohttp .GitHubAPI (session , "python/bedevere" , cache = cache )
40+ if not event .data .get ("installation" ):
41+ return web .Response (text = "Must be installed as an App." , status = 400 )
42+ installation_id = event .data ["installation" ]["id" ]
43+ installation_access_token = await apps .get_installation_access_token (
44+ gh ,
45+ installation_id = installation_id ,
46+ app_id = os .environ .get ("GH_APP_ID" ),
47+ private_key = os .environ .get ("GH_PRIVATE_KEY" ),
48+ )
49+ gh .oauth_token = installation_access_token ["token" ]
4050
41- if event .data .get ("installation" ):
42- # This path only works on GitHub App
43- installation_id = event .data ["installation" ]["id" ]
44- installation_access_token = await apps .get_installation_access_token (
45- gh ,
46- installation_id = installation_id ,
47- app_id = os .environ .get ("GH_APP_ID" ),
48- private_key = os .environ .get ("GH_PRIVATE_KEY" ),
49- )
50- gh .oauth_token = installation_access_token ["token" ]
5151 # Give GitHub some time to reach internal consistency.
5252 await asyncio .sleep (1 )
5353 await router .dispatch (event , gh , session = session )
@@ -63,7 +63,6 @@ async def main(request):
6363
6464@router .register ("installation" , action = "created" )
6565async def repo_installation_added (event , gh , * args , ** kwargs ):
66- # installation_id = event.data["installation"]["id"]
6766 print (
6867 f"App installed by { event .data ['installation' ]['account' ]['login' ]} , installation_id: { event .data ['installation' ]['id' ]} "
6968 )
0 commit comments