File size: 1,069 Bytes
071ba00
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from fastapi import FastAPI, HTTPException
from agent.core import run_agent

app = FastAPI()

@app.post('/webhook')
async def check_payload(payload: dict):
    if "action" in payload:
        if payload["action"] == "created":
            comment_body = payload["comment"]["body"] if "comment" in payload else ""
            if "@opensorus" in comment_body.lower():
                print("This issue is assigned to OpenSorus Agent.")
                issue_url = payload["issue"]["url"]
                print("URL", issue_url)
                branch_name = payload["repository"]["default_branch"]
                print("Branch Name", branch_name)
                result = await run_agent(issue_url, branch_name)
                return {"message": result or "This issue is assigned to OpenSorus Agent."}
        else:
            raise HTTPException(status_code=400, detail="Unknown action.")
    else:
        raise HTTPException(status_code=400, detail="No valid payload.")
    
@app.get('/health')
def health_check():
    return {"status": "Hello World!, I am alive!"}