diff --git a/main.py b/main.py index 050513b..f2dcc20 100644 --- a/main.py +++ b/main.py @@ -3,6 +3,8 @@ from pydantic import BaseModel from fastapi.middleware.cors import CORSMiddleware from calls import * from db import get_db_connection +import requests + app = FastAPI() app.add_middleware( @@ -393,4 +395,21 @@ def get_profile(request: ProfileRequest): raise HTTPException(status_code=400, detail=str(e)) finally: cursor.close() - conn.close() \ No newline at end of file + conn.close() + + + +@app.get("/version") +def get_latest_commit_hashes(): + try: + backend_response = requests.get("https://git.mercurio.moe/api/v1/repos/Mercury/dth-pingpong-backend/commits") + frontend_response = requests.get("https://git.mercurio.moe/api/v1/repos/Mercury/dth-pingpong-mobileapp/commits") + + if backend_response.status_code == 200 and frontend_response.status_code == 200: + backend_hash = backend_response.json()[0]["sha"] + frontend_hash = frontend_response.json()[0]["sha"] + return {"backend": backend_hash, "frontend": frontend_hash} + + return {"error": "Failed to fetch commit hashes from Forgejo"} + except Exception as e: + return {"error": str(e)} \ No newline at end of file