Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add new endpoint for devcontianer json raw #34

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 32 additions & 9 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from http.client import HTTPException
import logging
import os
import json
Expand Down Expand Up @@ -96,16 +97,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 +156,36 @@ 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: str):
if not repo_url:
return home()
try:
logging.info(f"Generating devcontainer.json for: {repo_url}")
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