7
7
8
8
from api .analyzers .source_analyzer import SourceAnalyzer
9
9
from api .git_utils import git_utils
10
+ from api .git_utils .git_graph import GitGraph
10
11
from api .graph import Graph , get_repos , graph_exists
11
12
from api .info import get_repo_info
12
13
from api .llm import ask
@@ -448,3 +449,41 @@ def switch_commit():
448
449
}
449
450
450
451
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