Skip to content
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
// auto-formatter for python
"[python]": {
"editor.defaultFormatter": "ms-python.autopep8",
"editor.defaultFormatter": "trunk.io",
"editor.formatOnSave": true,
},
// linting for python
Expand Down
4 changes: 2 additions & 2 deletions backend/app/api/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from .v1.auth import router as auth_router
from .v1.health import router as health_router
from .v1.integrations import router as integrations_router

from app.api.v1.repositories import router as repo_router
api_router = APIRouter()

api_router.include_router(
Expand All @@ -22,5 +22,5 @@
prefix="/v1/integrations",
tags=["Integrations"]
)

api_router.include_router(repo_router)
__all__ = ["api_router"]
24 changes: 24 additions & 0 deletions backend/app/api/v1/repositories.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from fastapi import APIRouter, HTTPException
from pydantic import BaseModel
from app.services.codegraph.repo_service import RepoService
import traceback

router = APIRouter(prefix="/api", tags=["repositories"])

class RepoRequest(BaseModel):
repo_url: str

@router.post("/repo-stats")
async def analyze_repository(request: RepoRequest):
print(f" repo aa gayi : {request.repo_url}")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Replace debug print with proper logging.

Debug print statements should not appear in production code and won't be captured by centralized logging systems.

Apply this diff to use proper logging:

+import logging
+
+logger = logging.getLogger(__name__)
+
 router = APIRouter(prefix="/api", tags=["repositories"])
 
 class RepoRequest(BaseModel):
     repo_url: str
 
 @router.post("/repo-stats")
 async def analyze_repository(request: RepoRequest):
-    print(f" repo aa gayi : {request.repo_url}")
+    logger.info(f"Repository analysis requested: {request.repo_url}")
🤖 Prompt for AI Agents
In backend/app/api/v1/repositories.py around line 13, replace the debug print
statement "print(f\" repo aa gayi : {request.repo_url}\")" with a proper logger
call (e.g., logger.debug or logger.info) that includes the repo URL and any
relevant request context; ensure the module imports or accesses the configured
logger (from your app logging setup or using logging.getLogger(__name__)),
remove the print, and use structured/clear message text so the event is captured
by centralized logs.


try:
result = await RepoService().index_repo(request.repo_url)
return {
"message": "Repository indexed successfully",
"repository": request.repo_url,
"stats": result
}
except Exception as e:
print(traceback.format_exc())
raise HTTPException(status_code=500, detail=str(e)) from e
Comment on lines +15 to +24
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Improve exception handling and logging.

Two issues with the current exception handling:

  1. Line 23 uses print() instead of proper logging
  2. Line 24 returns HTTP 500 for all exceptions, including client errors like ValueError from invalid repo URLs

Apply this diff to fix both issues:

+import logging
+
+logger = logging.getLogger(__name__)
+
 @router.post("/repo-stats")
 async def analyze_repository(request: RepoRequest):
-    print(f" repo aa gayi : {request.repo_url}")
+    logger.info(f"Repository analysis requested: {request.repo_url}")
 
     try:
         result = await RepoService().index_repo(request.repo_url)
         return {
             "message": "Repository indexed successfully",
             "repository": request.repo_url,
             "stats": result
         }
+    except ValueError as e:
+        logger.warning(f"Invalid repository URL: {request.repo_url} - {str(e)}")
+        raise HTTPException(status_code=400, detail=str(e)) from e
     except Exception as e:
-        print(traceback.format_exc()) 
+        logger.exception(f"Failed to index repository: {request.repo_url}")
         raise HTTPException(status_code=500, detail=str(e)) from e

Note: You can also remove the traceback import after this change.

Committable suggestion skipped: line range outside the PR's diff.

🧰 Tools
🪛 Ruff (0.14.4)

17-21: Consider moving this statement to an else block

(TRY300)

🤖 Prompt for AI Agents
In backend/app/api/v1/repositories.py around lines 15 to 24, replace the
print(traceback.format_exc()) and blanket HTTP 500 handling with proper logging
and selective HTTP responses: import and use the module logger (e.g., from
logging import getLogger; logger = getLogger(__name__)), call
logger.exception(...) to log the full stack trace, catch specific client errors
like ValueError and raise HTTPException(status_code=400, detail=str(e)) for
those, and keep a generic HTTPException(status_code=500, detail="Internal server
error") for unexpected exceptions; also remove the now-unneeded traceback
import.

2 changes: 1 addition & 1 deletion backend/app/services/codegraph/repo_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def _parse_repo_url(self, repo_input: str) -> Dict[str, str]:
"Expected: 'owner/repo' or 'https://github.com/owner/repo'"
)

async def index_repo(self, repo_input: str, discord_id: str) -> Dict[str, Any]:
async def index_repo(self, repo_input: str, discord_id: str = "web_user") -> Dict[str, Any]:
"""Index a GitHub repository."""
try:
# Parse repository URL
Expand Down