Skip to content

Commit

Permalink
add new endpoint for getting dev container raw data
Browse files Browse the repository at this point in the history
Signed-off-by: Rajesh Jonnalagadda <[email protected]>

chore: make repo_url optional

Signed-off-by: Rajesh Jonnalagadda <[email protected]>
  • Loading branch information
rajesh-jonnalagadda committed Nov 5, 2024
1 parent 2dbc975 commit 0eeef0a
Showing 1 changed file with 32 additions and 9 deletions.
41 changes: 32 additions & 9 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from http.client import HTTPException
import logging
import os
import json
from datetime import datetime
from typing import Optional
from fasthtml.common import *
from dotenv import load_dotenv
from supabase_client import supabase
Expand Down Expand Up @@ -96,16 +98,9 @@ def home():
footer_section()),
*scripts)

# Define routes
@rt("/")
async def get():
return home()

@rt("/generate", methods=["post"])
async def post(repo_url: str, regenerate: bool = False):
logging.info(f"Generating devcontainer.json for: {repo_url}")

# Normalize the repo_url by stripping trailing slashes
async def generateDevContainer(repo_url:str, regenerate=False):

repo_url = repo_url.rstrip('/')

try:
Expand Down Expand Up @@ -162,7 +157,35 @@ async def post(repo_url: str, regenerate: bool = False):
except Exception as e:
logging.error(f"Error while saving to database: {str(e)}")
raise

return devcontainer_json, source
except Exception as e:
logging.error(f"Error generating devcontainer.json: {str(e)}")
raise e


@rt("/", methods=["get"])
async def get(repo_url: Optional[str]=None):
if not repo_url:
return home()
try:
devcontainer_json, source = await generateDevContainer(repo_url)
return devcontainer_json
except Exception as e:
logging.error(f"Error generating devcontainer.json: {str(e)}")
raise HTTPException(500, f"An error occurred while generating the devcontainer.json: {str(e)}")


@rt("/generate", methods=["post"])
async def post(repo_url: str, regenerate: bool = False):
logging.info(f"Generating devcontainer.json for: {repo_url}")

# Normalize the repo_url by stripping trailing slashes
repo_url = repo_url.rstrip('/')

try:
devcontainer_json, source = await generateDevContainer(repo_url, regenerate=regenerate)

return Div(
Article(f"Devcontainer.json {'found in ' + source if source in ['database', 'repository'] else 'generated'}"),
Pre(
Expand Down

0 comments on commit 0eeef0a

Please sign in to comment.