11""" Main API module for CodeGraph. """
2+ import logging
23import os
34from pathlib import Path
45from functools import wraps
1819load_dotenv ()
1920
2021# Configure the logger
21- import logging
2222logging .basicConfig (level = logging .DEBUG ,
2323 format = '%(asctime)s - %(name)s - %(levelname)s - %(message)s' )
2424logger = logging .getLogger (__name__ )
@@ -38,6 +38,7 @@ def decorated_function(*args, **kwargs):
3838 return f (* args , ** kwargs )
3939 return decorated_function
4040
41+
4142app = Flask (__name__ )
4243
4344def public_access (f ):
@@ -109,7 +110,7 @@ def get_neighbors():
109110 data = request .get_json ()
110111
111112 # Get query parameters
112- repo = data .get ('repo' )
113+ repo = data .get ('repo' )
113114 node_ids = data .get ('node_ids' )
114115
115116 # Validate 'repo' parameter
@@ -298,7 +299,7 @@ def find_paths():
298299 paths = g .find_paths (src , dest )
299300
300301 # Create and return a successful response
301- response = { 'status' : 'success' , 'paths' : paths }
302+ response = {'status' : 'success' , 'paths' : paths }
302303
303304 return jsonify (response ), 200
304305
@@ -323,7 +324,7 @@ def chat():
323324 answer = ask (repo , msg )
324325
325326 # Create and return a successful response
326- response = { 'status' : 'success' , 'response' : answer }
327+ response = {'status' : 'success' , 'response' : answer }
327328
328329 return jsonify (response ), 200
329330
@@ -346,8 +347,8 @@ def analyze_folder():
346347 data = request .get_json ()
347348
348349 # Get query parameters
349- path = data .get ('path' )
350- ignore = data .get ('ignore' , [])
350+ path = data .get ('path' )
351+ ignore = data .get ('ignore' , [])
351352
352353 # Validate input parameters
353354 if not path :
@@ -375,9 +376,9 @@ def analyze_folder():
375376
376377 # Return response
377378 response = {
378- 'status' : 'success' ,
379- 'project' : proj_name
380- }
379+ 'status' : 'success' ,
380+ 'project' : proj_name
381+ }
381382 return jsonify (response ), 200
382383
383384@app .route ('/analyze_repo' , methods = ['POST' ])
@@ -409,9 +410,12 @@ def analyze_repo():
409410 proj .analyze_sources (ignore )
410411 proj .process_git_history (ignore )
411412
412- # Create a response
413+ stats = proj .graph .stats ()
414+
413415 response = {
414416 'status' : 'success' ,
417+ 'node_count' : stats .get ('node_count' , 0 ),
418+ 'edge_count' : stats .get ('edge_count' , 0 )
415419 }
416420
417421 return jsonify (response ), 200
@@ -472,7 +476,7 @@ def list_commits():
472476 # Validate the presence of the 'repo' parameter
473477 repo = data .get ('repo' )
474478 if repo is None :
475- return jsonify ({'status' : f 'Missing mandatory parameter "repo"' }), 400
479+ return jsonify ({'status' : 'Missing mandatory parameter "repo"' }), 400
476480
477481 # Initialize GitGraph object to interact with the repository
478482 git_graph = GitGraph (git_utils .GitRepoName (repo ))
@@ -486,4 +490,4 @@ def list_commits():
486490 'commits' : commits
487491 }
488492
489- return jsonify (response ), 200
493+ return jsonify (response ), 200
0 commit comments