diff --git a/api/index.py b/api/index.py index 3f7c50b..50b17c7 100644 --- a/api/index.py +++ b/api/index.py @@ -7,6 +7,7 @@ from api.analyzers.source_analyzer import SourceAnalyzer from api.git_utils import git_utils +from api.git_utils.git_graph import GitGraph from api.graph import Graph, get_repos, graph_exists from api.info import get_repo_info from api.llm import ask @@ -448,3 +449,41 @@ def switch_commit(): } return jsonify(response), 200 + +@app.route('/list_commits', methods=['POST']) +@public_access # Apply public access decorator +@token_required # Apply token authentication decorator +def list_commits(): + """ + Endpoint to list all commits of a specified repository. + + Request JSON Structure: + { + "repo": "repository_name" + } + + Returns: + JSON response with a list of commits or an error message. + """ + + # Get JSON data from the request + data = request.get_json() + + # Validate the presence of the 'repo' parameter + repo = data.get('repo') + if repo is None: + return jsonify({'status': f'Missing mandatory parameter "repo"'}), 400 + + # Initialize GitGraph object to interact with the repository + git_graph = GitGraph(git_utils.GitRepoName(repo)) + + # Fetch commits from the repository + commits = git_graph.list_commits() + + # Return success response with the list of commits + response = { + 'status': 'success', + 'commits': commits + } + + return jsonify(response), 200 \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index cc2bd29..b817a1f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "code-graph-backend" -version = "0.4.1" +version = "0.4.2" description = "code_graph is designed to help developers visualize and analyze the structure of their source code. It takes source code as input and generates a graph representation, making it easier to understand relationships and dependencies within the codebase." authors = ["Roi Lipman "] readme = "README.md"