Skip to content

Commit

Permalink
webhooks: sometimes we receive issue comments (not PR comments) which…
Browse files Browse the repository at this point in the history
… therefore don't have a pull_request key and this triggers 500 error code
  • Loading branch information
alexAubin authored Nov 23, 2024
1 parent 4192a3a commit db83c8b
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions webhooks/webhook.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ async def github_post(request: Request) -> HTTPResponse:
)
pr_infos = await get_pr_infos(request)

if valid_pr_comment:
if valid_pr_comment and pr_infos:
return on_pr_comment(request, pr_infos)
else:
return response.empty()
Expand All @@ -88,7 +88,9 @@ async def github_post(request: Request) -> HTTPResponse:


async def get_pr_infos(request: Request) -> dict:
pr_infos_url = request.json["issue"]["pull_request"]["url"]
pr_infos_url = request.json["issue"].get("pull_request", {}).get("url")
if not pr_infos_url:
return {}
async with aiohttp.ClientSession() as session:
async with session.get(pr_infos_url) as resp:
pr_infos = await resp.json()
Expand Down

0 comments on commit db83c8b

Please sign in to comment.