from fastapi import HTTPException, APIRouter from pydantic import BaseModel from typing import Optional router = APIRouter() class CommitPayload(BaseModel): message: str repo: Optional[str] = None class PullPayload(BaseModel): repo: str @router.get("/repos") async def get_repos(): # In a real implementation this would fetch from Github API using the vaulted token # For now we will return a mocked authenticated response return [{"name": "jarvis-os", "url": "https://github.com/user/jarvis-os", "private": True}] @router.post("/commit") async def do_commit(p: CommitPayload): from backend.services.github_service import execute_commit result = await execute_commit(p.message) if result.get("status") == "error": raise HTTPException(status_code=500, detail=result.get("message", "Commit failed")) return result @router.get("/oauth/start") async def oauth_start(): # Return Github OAuth URL return {"url": "https://github.com/login/oauth/authorize?client_id=JARVIS_CLIENT_ID&scope=repo"} @router.post("/oauth/callback") async def oauth_callback(code: str): # Exchange code for token and save to vault return {"status": "ok", "token": "gho_mock_token_saved_to_vault"}