Elizabeth Thomas
Initial commit
01c2bb8
raw
history blame contribute delete
992 Bytes
import httpx
from fastapi import FastAPI, Request
from fastapi.responses import JSONResponse
app = FastAPI()
headers = {
"Content-Type": "application/json"
}
async def handle_webhook(request: Request):
data = await request.json()
if "pull_request" in data.keys() and (
data["action"] in ["opened", "reopened"]
): # use "synchronize" for tracking new commits
pr = data.get("pull_request")
# Greet the user and show instructions.
async with httpx.AsyncClient() as client:
await client.post(
f"{pr['issue_url']}/comments",
json={"body": "Hello from code review assistant"},
headers=headers,
)
return JSONResponse(content={}, status_code=200)
@app.get("/")
async def root():
return {"message": "Code review assistant reporting for duty!"}
@app.post("/webhook/")
async def handle_webhook_route(request: Request):
return await handle_webhook(request)