-
Notifications
You must be signed in to change notification settings - Fork 8
Process local folder #35
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,77 +1,44 @@ | ||
# Python | ||
# Byte-compiled files | ||
*.pyc | ||
*.pyo | ||
*.pyd | ||
__pycache__/ | ||
*.env | ||
.venv/ | ||
env/ | ||
venv/ | ||
ENV/ | ||
*.egg-info/ | ||
*.egg | ||
pip-log.txt | ||
|
||
# Flask | ||
instance/ | ||
*.sqlite3 | ||
*.db | ||
*.bak | ||
instance/config.py | ||
instance/*.secret | ||
|
||
# Environment Variables | ||
.env | ||
.env.* | ||
|
||
# Logs | ||
logs/ | ||
*.log | ||
*.out | ||
*.err | ||
# Virtual environments | ||
venv/ | ||
env/ | ||
.virtualenv/ | ||
|
||
# Pytest and Coverage | ||
.pytest_cache/ | ||
.coverage | ||
.tox/ | ||
nosetests.xml | ||
coverage.xml | ||
*.cover | ||
.cache | ||
# Distribution/build files | ||
build/ | ||
dist/ | ||
*.egg-info/ | ||
.eggs/ | ||
|
||
# IDEs and Editors | ||
# IDE settings | ||
.vscode/ | ||
.idea/.env | ||
.vercel | ||
|
||
# ignore the .pyc files | ||
*.pyc | ||
|
||
dist/ | ||
# Node (if using npm/yarn for assets) | ||
node_modules/ | ||
*.lock | ||
.idea/ | ||
*.swp | ||
|
||
# Static assets (if generated) | ||
static/ | ||
dist/ | ||
build/ | ||
# Logs and debugging | ||
*.log | ||
*.trace | ||
|
||
# Docker | ||
*.pid | ||
docker-compose.override.yml | ||
# OS-specific files | ||
.DS_Store | ||
Thumbs.db | ||
|
||
# Heroku | ||
*.buildpacks | ||
*.env.local | ||
*.env.production | ||
*.env.*.local | ||
# Testing and coverage | ||
htmlcov/ | ||
*.cover | ||
.coverage | ||
.cache/ | ||
pytest_cache/ | ||
|
||
# Miscellaneous | ||
*.bak | ||
*.tmp | ||
*.log.* | ||
Thumbs.db | ||
# Jupyter Notebook checkpoints | ||
.ipynb_checkpoints/ | ||
|
||
# Vercel | ||
.vercel | ||
# Custom settings | ||
.env | ||
*.sqlite3 | ||
.vercel |
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,6 +1,7 @@ | ||||||||||||
import os | ||||||||||||
import datetime | ||||||||||||
from api import * | ||||||||||||
from pathlib import Path | ||||||||||||
Comment on lines
3
to
+4
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Replace star import with explicit imports Star imports ( Replace with explicit imports: -from api import *
+from api.analyzers.source_analyzer import SourceAnalyzer
+from api.graph import Graph
+from api.utils import graph_exists, get_repos, get_repo_info, ask
🧰 Tools🪛 Ruff (0.8.0)3-3: (F403) |
||||||||||||
from typing import Optional | ||||||||||||
from functools import wraps | ||||||||||||
from falkordb import FalkorDB | ||||||||||||
|
@@ -309,3 +310,57 @@ def chat(): | |||||||||||
response = { 'status': 'success', 'response': answer } | ||||||||||||
|
||||||||||||
return jsonify(response), 200 | ||||||||||||
|
||||||||||||
@app.route('/analyze_folder', methods=['POST']) | ||||||||||||
@token_required # Apply token authentication decorator | ||||||||||||
def analyze_folder(): | ||||||||||||
""" | ||||||||||||
Endpoint to analyze local source code | ||||||||||||
Expects 'path' and optionally an ignore list. | ||||||||||||
|
||||||||||||
Returns: | ||||||||||||
JSON response with status and error message if applicable | ||||||||||||
Status codes: | ||||||||||||
200: Success | ||||||||||||
400: Invalid input | ||||||||||||
500: Internal server error | ||||||||||||
""" | ||||||||||||
|
||||||||||||
# Get JSON data from the request | ||||||||||||
data = request.get_json() | ||||||||||||
|
||||||||||||
# Get query parameters | ||||||||||||
path = data.get('path') | ||||||||||||
ignore = data.get('ignore', []) | ||||||||||||
|
||||||||||||
# Validate input parameters | ||||||||||||
if not path: | ||||||||||||
logging.error("'path' is missing from the request.") | ||||||||||||
return jsonify({"status": "'path' is required."}), 400 | ||||||||||||
|
||||||||||||
# Validate path exists and is a directory | ||||||||||||
if not os.path.isdir(path): | ||||||||||||
logging.error(f"Path '{path}' does not exist or is not a directory") | ||||||||||||
return jsonify({"status": "Invalid path: must be an existing directory"}), 400 | ||||||||||||
|
||||||||||||
# Validate ignore list contains valid paths | ||||||||||||
if not isinstance(ignore, list): | ||||||||||||
logging.error("'ignore' must be a list of paths") | ||||||||||||
return jsonify({"status": "'ignore' must be a list of paths"}), 400 | ||||||||||||
|
||||||||||||
proj_name = Path(path).name | ||||||||||||
|
||||||||||||
Comment on lines
+351
to
+352
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Add validation for project name The project name is derived from the path without validation, which could lead to issues with special characters or empty names. Add validation: - proj_name = Path(path).name
+ proj_name = Path(path).name
+ if not proj_name or proj_name.startswith('.'):
+ logging.error(f"Invalid project name derived from path: {proj_name}")
+ return jsonify({"status": "Invalid path: cannot derive valid project name"}), 400 📝 Committable suggestion
Suggested change
|
||||||||||||
# Initialize the graph with the provided project name | ||||||||||||
g = Graph(proj_name) | ||||||||||||
|
||||||||||||
# Analyze source code within given folder | ||||||||||||
analyzer = SourceAnalyzer() | ||||||||||||
analyzer.analyze_local_folder(path, g, ignore) | ||||||||||||
|
||||||||||||
# Return response | ||||||||||||
response = { | ||||||||||||
'status': 'success', | ||||||||||||
'project': proj_name | ||||||||||||
} | ||||||||||||
return jsonify(response), 200 | ||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix mutable default argument
Using mutable default arguments in Python can lead to unexpected behavior. The empty list
[]
as a default argument is shared across function calls.Replace with:
And add at the beginning of the method:
🧰 Tools
🪛 Ruff (0.8.0)
138-138: Do not use mutable data structures for argument defaults
Replace with
None
; initialize within function(B006)