77
88from api .analyzers .source_analyzer import SourceAnalyzer
99from api .git_utils import git_utils
10+ from api .git_utils .git_graph import GitGraph
1011from api .graph import Graph , get_repos , graph_exists
1112from api .info import get_repo_info
1213from api .llm import ask
@@ -448,3 +449,41 @@ def switch_commit():
448449 }
449450
450451 return jsonify (response ), 200
452+
453+ @app .route ('/list_commits' , methods = ['POST' ])
454+ @public_access # Apply public access decorator
455+ @token_required # Apply token authentication decorator
456+ def list_commits ():
457+ """
458+ Endpoint to list all commits of a specified repository.
459+
460+ Request JSON Structure:
461+ {
462+ "repo": "repository_name"
463+ }
464+
465+ Returns:
466+ JSON response with a list of commits or an error message.
467+ """
468+
469+ # Get JSON data from the request
470+ data = request .get_json ()
471+
472+ # Validate the presence of the 'repo' parameter
473+ repo = data .get ('repo' )
474+ if repo is None :
475+ return jsonify ({'status' : f'Missing mandatory parameter "repo"' }), 400
476+
477+ # Initialize GitGraph object to interact with the repository
478+ git_graph = GitGraph (git_utils .GitRepoName (repo ))
479+
480+ # Fetch commits from the repository
481+ commits = git_graph .list_commits ()
482+
483+ # Return success response with the list of commits
484+ response = {
485+ 'status' : 'success' ,
486+ 'commits' : commits
487+ }
488+
489+ return jsonify (response ), 200
0 commit comments