MCPcopy Index your code
hub / github.com/hunvreus/devpush / github_webhook

Function github_webhook

app/routers/github.py:437–609  ·  view source on GitHub ↗
(
    request: Request,
    webhook_data: tuple[dict, str] = Depends(_verify_github_webhook),
    db: AsyncSession = Depends(get_db),
    redis_client: Redis = Depends(get_redis_client),
    queue: ArqRedis = Depends(get_queue),
)

Source from the content-addressed store, hash-verified

435
436@router.post("/webhook", name="github_webhook")
437async def github_webhook(
438 request: Request,
439 webhook_data: tuple[dict, str] = Depends(_verify_github_webhook),
440 db: AsyncSession = Depends(get_db),
441 redis_client: Redis = Depends(get_redis_client),
442 queue: ArqRedis = Depends(get_queue),
443):
444 try:
445 data, event = webhook_data
446
447 logger.info(f"Received GitHub webhook event: {event}")
448
449 match event:
450 case "installation":
451 if data["action"] in ["deleted", "suspended", "unsuspended"]:
452 # App uninstalled or suspended
453 status = (
454 "active" if data["action"] == "unsuspended" else data["action"]
455 )
456 await db.execute(
457 update(GithubInstallation)
458 .where(
459 GithubInstallation.installation_id
460 == data["installation"]["id"]
461 )
462 .values(status=status)
463 )
464 await db.commit()
465 logger.info(
466 f"Installation {data['installation']['id']} for {data['installation']['account']['login']} is {data['action']}"
467 )
468
469 elif data["action"] == "created":
470 # App installed
471 installation_id = data["installation"]["id"]
472 github_service = get_github_service()
473 token_data = await github_service.get_installation_access_token(
474 installation_id
475 )
476 installation = GithubInstallation(
477 installation_id=installation_id,
478 token=token_data["token"],
479 token_expires_at=datetime.fromisoformat(
480 token_data["expires_at"].replace("Z", "+00:00")
481 ),
482 )
483 await db.merge(installation)
484 await db.commit()
485 logger.info(
486 f"Installation {installation_id} for {data['installation']['account']['login']} created"
487 )
488
489 case "installation_target":
490 if data["action"] == "renamed":
491 # Installation account is renamed (not used)
492 pass
493
494 case "installation_repositories":

Callers

nothing calls this directly

Calls 6

createMethod · 0.95
get_github_serviceFunction · 0.90
GithubInstallationClass · 0.90
DeploymentServiceClass · 0.90
rollbackMethod · 0.80

Tested by

no test coverage detected