-
Notifications
You must be signed in to change notification settings - Fork 7
/
app.py
27 lines (23 loc) · 811 Bytes
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
from fastapi import FastAPI, APIRouter, HTTPException, Request, Response
from reviewer import review_pr
router = APIRouter()
@router.post("/github_webhooks")
async def handle_github_webhooks(request: Request, response: Response):
print("Received a github webhook")
body = await request.json()
print(body)
action = body.get("action", None)
# number = body.get("number", None)
pull_request = body.get("pull_request", {})
if action == "opened" or action == "reopened":
html_url = pull_request.get("html_url", None)
if html_url is None:
return {}
try:
msg = review_pr(html_url)
print(msg)
except Exception as e:
print(e)
return {}
app = FastAPI()
app.include_router(router, prefix="/api/v1")